Install third party JAR not available in MAVEN central
Maven is a build automation tool used to build projects written in Java, C#, Ruby, Scala and many other languages. Sometime, we don’t find the JAR in the maven. Or may be some proprietary JAR which we can not publish publicly on the Maven.
There are two options:
- Maven install plugin
- Install JAR in maven local repository
1. Maven install plugin
Using maven install plugin, it’s easy to add the JAR into the classpath. One advantage is this classpath JAR is, it is included in the fat JAR.
- Most important section is <configuration>.
- Add the groupId, artifactId and version according to your requirements.
- Add the JAR file inside the project base directory or any other continent directory of your choice. In the example above, I placed the JAR in the project base directory, inside the dependency directory.
- Make sure you download the latest plugin from the maven central, available here – Maven Install Plugin – latest version
Now, you are all set to build the project using:
mvn clean install
2. Install JAR in maven local repository
To make compiler happy, this method is used. It installs the JAR into the local Maven repository (.m2 directory). Note: JAR is not included when you create a fat JAR of your project. Third party JAR still resides in the local Maven repository.
$mvn install:install-file -Dfile=F:\my-project-10.1.1.jar
-DgroupId=com.aniket.myorg.project
-DartifactId=my-project
-Dversion=10.1.1 -Dpackaging=jar
The command is self explanatory. The my-project JAR is copied into the local Maven repository. Now, you can add the JAR as maven dependency in your pom.xml as:
<dependency>
<groupId>com.aniket.myorg.project</groupId>
<artifactId>my-project</artifactId>
<version>10.1.1</version>
</dependency>
This will resolve the JAR from the local repository.
The easiest way, apart from the install command is to use the “<systemPath>” tag in the pom.xml itself. Here is an example.
<dependency>
<groupId>com.aniket.myorg.project</groupId>
<artifactId>my-project</artifactId>
<version>10.1.1</version>
<scope>system</scope>
<systemPath>F:/my-project-10.1.1.jar</systemPath>
</dependency>
Please leave a comment/feedback.