How To Install a Jar File In The Maven Local Repository
When developing some maven projects, we may need to use some third-party jar libraries. But because of some reasons, they are not available in Maven repository. Therefore we can not add them into pom.xml
file like other libraries.
There are two ways to do this:
Let’s assume you want to use json-1.0.0.jar
library for the project.
1. Add local dependencies directly
You will need to put the jar dependency file in your WEB-INF/lib/
directory. Then use it in pom.xml
file like this:
pom.xml
<dependency>
<groupId>thirdparty.com</groupId>
<artifactId>json</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/json-1.0.0.jar</systemPath>
</dependency>
2. Use install:install-file
Run the below command:
mvn install:install-file -Dfile=json-1.0.0.jar -DgroupId=thirdparty.com -DartifactId=json -Dversion=1.0.0 -Dpackaging=jar
In the command, you will need to change the following information based on your jar file: -Dfile
, DgroupId
, -DarticfacId
, and -Dversion
.
Now you use it as a dependency in pom.xml
file:
pom.xml
<dependency>
<groupId>thirdparty.com</groupId>
<artifactId>json</artifactId>
<version>1.0.0</version>
</dependency>