How to install a custom library or jar in the maven local repository

Imran Shaikh
0

Have you ever wonder about using a third-party library, or a jar in the maven project and that is not available in the maven remote repository?


In this article, I'll walk you through how to install a custom library in a local maven repository. Installing a custom library in the local maven repository is a cakewalk.


In this article, I'll demonstrate how to install a custom library in the local maven repository using two methods.

How to install custom library or jar in local maven repository thumbnail
toc

How to install custom library or jar using the maven


To install the custom library or jar in the local maven repository, you must have installed a maven in your machine. To check if the maven is installed on your computer, type the following command in your terminal (CMD, If you are using windows).


mvn --version(code-box)

If you haven't installed a maven on your computer, you can skip stepping 2.


If you get the following information, then it means the maven is working on your machine.


 Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
 Maven home: C:\Program Files\apache-maven-3.6.3\bin\..
 Java version: 1.8.0_111, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_111\jre
 Default locale: en_IN, platform encoding: Cp1252
 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Maven template to install the custom library


mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>(code-box)

Example of the installing custom library

 C:\Users\Imran Shaikh>mvn install:install-file -Dfile=G:\jars\jersey-client-2.31.jar -DgroupId=com.jersey.client -DartifactId=jersey-client -Dversion=2.31 -Dpackaging=jar
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------< org.apache.maven:standalone-pom >-------------------
    [INFO] Building Maven Stub Project (No POM) 1
    [INFO] --------------------------------[ pom ]---------------------------------
    [INFO]
    [INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
    [INFO] Installing G:\jars\jersey-client-2.31.jar to C:\Users\Imran Shaikh\.m2\repository\com\jersey\client\jersey-client\2.31\jersey-client-2.31.jar
    [INFO] Installing C:\Users\IMRANS~1\AppData\Local\Temp\mvninstall6228289163983509785.pom to C:\Users\Imran Shaikh\.m2\repository\com\jersey\client\jersey-client\2.31\jersey-client-2.31.pom
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  1.855 s
    [INFO] Finished at: 2020-10-22T17:42:33+05:30
    [INFO] ------------------------------------------------------------------------

Adding dependency in the pom.xml

After installing the custom library in the local maven repository, now add that dependency in the pom.xml to use it.


 <dependency>
    <groupId>com.jersey.client</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.31</version>
 </dependency>

How to install custom library or jar using eclipse or spring toll suite IDE


We can also install a custom library or jar using the eclipse or spring tool suite IDE.


Right-click on the pom.xml, run as, Maven Build as shown in the below screen.


pom.xml run as maven build.

Now use the same template which I mention in step 1.1 But remove the word mvn. For e.g,


install:install-file -Dfile=G:\jars\jersey-client-2.31.jar -DgroupId=com.jersey.client -DartifactId=jersey-client -Dversion=2.31 -Dpackaging=jar(code-box)

Now type the installation command in the goal section as shown in the below image.


Adding installation cammand in goal section

Now hit enter and check your IDE console


 [INFO] Scanning for projects...
    [INFO] 
    [INFO] --------------< in.learnjavaskills:SpringDataJPATutorial >--------------
    [INFO] Building SpringDataJPATutorial 1.0
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] 
    [INFO] --- maven-install-plugin:2.5.2:install-file (default-cli) @ SpringDataJPATutorial ---
    [INFO] Installing G:\jars\jersey-client-2.31.jar to C:\Users\Imran Shaikh\.m2\repository\com\jersey\client\jersey-client\2.31\jersey-client-2.31.jar
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  3.274 s
    [INFO] Finished at: 2020-10-22T18:12:50+05:30
    [INFO] ------------------------------------------------------------------------

Conclusion


In this tutorial, we saw two different ways to install a custom library or jar in the local maven repository. First, we had installed the jersey-client jar using the maven in CMD and then we also installed the jersey-client jar using the eclipse IDE.


If you have any doubts related to this tutorial, Feel free to drop a message in the comment box.


Thanks for reading and keep learning, keep growing.

Tags

Post a Comment

0 Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top