Having a 3rd party jar included in Maven shaded jar without adding it to local repository
But, when I use the Maven Shade Plugin to create a JAR that includes all the dependencies of the project as well, the 3rd party JAR is not included automatically.
Yes, because the
system scoped dependencies are assumed to be always present (this is exactly what the
system scope is about) so they won't be included. People actually don't understand what
system scope dependencies are, they just keep abusing them (yes, this is abuse), and then get side effects and wonder why (as Brian pointed out in his answer).
I already wrote many, many, really many times about this here on SO and in 99% of the cases,
system scoped dependencies should be avoided. And I'll repeat what the Dependency Scopes mini guide says one more time:
system: This dependency is required in some phase of your project's lifecycle, but is system-specific. Use of this scope is discouraged: This is considered an "advanced" kind of feature and should only be used when you truly understand all the ramifications of its use, which can be extremely hard if not actually impossible to quantify. This scope by definition renders your build non-portable. It may be necessary in certain edge cases. The system scope includes the
<systemPath>element which points to the physical location of this dependency on the local machine. It is thus used to refer to some artifact expected to be present on the given local machine an not in a repository; and whose path may vary machine-to-machine. The systemPath element can refer to environment variables in its path:
So, instead of using the
system scope, either:
- Add your libraries to your local repository via
install:install-file. This is a quick and dirty way to get things working, it might be an option if you're alone but it makes your build non portable.
- Install and run an "enterprise repository" like Nexus, Archiva, or Artifactory and add your libraries via
deploy:deploy-file. This is the ideal scenario.
- Setup a file based repository as described in this previous answer and put your libraries in there. This is the best compromise if you don't have a corporate repository but need to work as a team and don't want to sacrifice portability.
Please, stop using the
Including a non-Mavenized dependency so it works with maven-shade-plugin
you want to check the maven docs on installing 3rd party jars
Once installed into your local maven repository, shade should be able to use them like any other dependency.
How to add local jar files to a Maven project?
Install the JAR into your local Maven repository (typically
.m2 in your home folder) as follows:
mvn install:install-file \
Where each refers to:
<path-to-file>: the path to the file to load e.g →
<group-id>: the group that the file should be registered under e.g →
<artifact-id>: the artifact name for the file e.g →
<version>: the version of the file e.g →
<packaging>: the packaging of the file e.g. →
- Maven FAQ: I have a jar that I want to put into my local repository. How can I copy it in?
- Maven Install Plugin Usage: The
Creation of executable jar with maven, spring boot and repo-less 3rd party libs fail either way
Have you consider setting up an internal maven repository ? The easiest one will be Apache Archival (https://archiva.apache.org/index.cgi):
For Apache Archival, you can actually manually copy your third party libraries into the maven repository.
In your pom.xml, you have to add in the following:
<name>Archiva Managed Internal Repository</name>
How to include local jar files in Maven project
Have you considered adding those two JARs as
system dependencies? e.g.,
Just a word of note, this is NOT recommended and should be used very sparingly, if ever.
Chromedriver and Webdriver for Selenium Through Testng Results in 4 Errors
Create a Jtds Connection String
Log4J: How to Use Socketappender
Java Swing: How to Implement a Login Screen Before Showing a Jframe
Comparing Arrays in Junit Assertions, Concise Built-In Way
How to Keep the Iteration Order of a List When Using Collections.Tomap() on a Stream
How to Read a File from a Jar File
Is the Java Hashmap Keyset() Iteration Order Consistent
How to Draw an Image Over Another Image
How to Determine If a List Is Sorted in Java
Performance of Stringtokenizer Class VS. String.Split Method in Java
What Is the Replacement for Javax.Activation Package in Java 9
Simple Way to Count Character Occurrences in a String
Is There a Newline Constant Defined in Java Like Environment.Newline in C#
JSONmanagedreference VS JSONbackreference