How do I add local jar files (not yet part of the Maven repository) directly in my project's library sources?
Another solution is to use the maven-install-plugin in your pom. xml which will install the jar during the Maven “initialize” phase. To do this, you must specify the location of the jar you want to install. The best way is to put the JAR in a folder created at the root of the project (in the same directory as the pom.
Approach 2: Include jar as part of the maven project. In this approach you need to first create a folder in your maven project & add your external jar file. Once the jar file is added, include the jar file in your pom using following notation.
Install the JAR into your local Maven repository (typically .m2
in your home folder) as follows:
mvn install:install-file \ -Dfile=<path-to-file> \ -DgroupId=<group-id> \ -DartifactId=<artifact-id> \ -Dversion=<version> \ -Dpackaging=<packaging> \ -DgeneratePom=true
Where each refers to:
<path-to-file>
: the path to the file to load e.g → c:\kaptcha-2.3.jar
<group-id>
: the group that the file should be registered under e.g → com.google.code
<artifact-id>
: the artifact name for the file e.g → kaptcha
<version>
: the version of the file e.g → 2.3
<packaging>
: the packaging of the file e.g. → jar
Reference
install:install-file
goal You can add local dependencies directly (as mentioned in build maven project with propriatery libraries included) like this:
<dependency> <groupId>com.sample</groupId> <artifactId>sample</artifactId> <version>1.0</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/Name_Your_JAR.jar</systemPath> </dependency>
Update
In new releases this feature is marked as deprecated but still working and not removed yet ( You just see warning in the log during maven start). An issue is raised at maven group about this https://issues.apache.org/jira/browse/MNG-6523 ( You can participate and describe why this feature is helpful in some cases). I hope this feature remains there!
If you are asking me, as long as the feature is not removed, I use this to make dependency to only one naughty jar file in my project which is not fit in repository. If this feature is removed, well, there are lots of good answers here which I can chose from later!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With