maven logo

How to install local jars into maven local repository

When you develop maven java project sometime you will get issue is some jars library that you need but not yet or not exist on maven center repository, so how you can make your project build work with these issues. In this post i will guide you how to install local jars into maven local repository.

To install local jars into maven local repository, you can use following command

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

To demonstrate for this command i will install com.sun.net.ssl.jar to my maven local repository.

1. Maven install

Copy com.sun.net.ssl.jar to directory that we want to read from in my example it is D:\ and run command below

mvn install:install-file -Dfile=D:\com.sun.net.ssl.jar -DgroupId=com.sun.net -DartifactId=ssl -Dversion=1.0 -Dpackaging=jar

Sample output of this command

\>mvn install:install-file -Dfile=D:\com.sun.net.ssl.jar -DgroupId=com.sun.net
 -DartifactId=ssl -Dversion=1.0 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom
---
[INFO] Installing D:\com.sun.net.ssl.jar to C:\Users\ThaiThinh\.m2\repository\co
m\sun\net\ssl\1.0\ssl-1.0.jar
[INFO] Installing C:\Users\THAITH~1\AppData\Local\Temp\mvninstall837714260042505
0833.pom to C:\Users\ThaiThinh\.m2\repository\com\sun\net\ssl\1.0\ssl-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.830s
[INFO] Finished at: Tue Mar 03 14:23:31 ICT 2015
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
D:\>

2. Use the library in local

To involve this library on your project, now we just need add follow dependent to our pom.xml file

<dependency>
      <groupId>com.sun.net</groupId>
      <artifactId>ssl</artifactId>
      <version>1.0</version>
 </dependency>

Leave a Reply