Buy @ Amazon

Manually installing jars in Maven Repository

Occasionally we stumble upon a situation where in we may find dependency of a jar that falls under the following category:
  • it is propriety jar file which will never be part of maven repository
  • it is not in official maven repository, for whatever reason it be
In this situation, you add this jar (“install” in Maven’s jargon) to your local Maven repository. How do you do this?

If you know and\or understand the layout of the maven repository, you can copy the jar directly into where it is meant to go. Maven will find this file next time it is run.

If you are not confident about the layout of the maven repository, then you can adapt the command below to load in your jar file.

mvn install:install-file
  -Dfile=<path-to-file>
  -DgroupId=<group-id>
  -DartifactId=<artifact-id>
  -Dversion=<version>
  -Dpackaging=<packaging>
  -DgeneratePom=true
Where: 
<path-to-file>  the path to the file to load
<group-id>      the group that the file should be registered under
<artifact-id>   the artifact name for the file
<version>       the version of the file
<packaging>     the packaging of the file e.g. jar
For example, I had to once download and install “simple-xml-1.6.1-mod.jar” to my local maven repository. For this I installed the jar by running the following command:
mvn install:install-file
-Dfile= C:\Users\kartz\Desktop\simple-xml-1.6.1-mod.jar 
-DgroupId=org.simpleframework 
-DartifactId=simple-xml 
-Dversion=1.6.1-mod 
-Dpackaging=jar 
This should load in the file\jar into your local maven repository. After this step you may then make the required dependency entry into the pom.xml. The dependency entry in my case would be like the entry below:
<dependency>
   <groupId>org.simpleframework</groupId>
   <artifactId></artifactId>
   <version>1.6.1-mod</version>
</dependency>

By observing the command that I had run above and the dependency entry we can find that this pom entry is only a translation of the command that I had run earlier.

It is important to note that the Maven may not recognize this entry because it always searches for dependency jars from the repositories defined in the <repository>..</repository> tag.