Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add local jar files to a Maven project?

How do I add local jar files (not yet part of the Maven repository) directly in my project's library sources?

like image 978
Praneel PIDIKITI Avatar asked Feb 10 '11 10:02

Praneel PIDIKITI


People also ask

How do I add local jars in POM xml?

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.

Can we add external jar in Maven project?

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.


2 Answers

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

  • 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 install:install-file goal
like image 25
user373455 Avatar answered Oct 04 '22 08:10

user373455


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!

like image 91
Alireza Fattahi Avatar answered Oct 04 '22 08:10

Alireza Fattahi