How to add or install local jar files to the Maven Project ?
This tutorial guides you on how to add or install local jar files to the Maven Project. Sometimes you may need to install third party JARs or local JARs to the Maven Project. Let’s see how to do that with example.
Add or install local jar files to the Maven Project
Let’s say for example, mvn install fails to install the specific version of Jakarta Activation jar lib, so that you have a local jar called “jakarta.activation-2.0.1.jar” in your local path C:\Users\91990\Documents\Sneppets\work.
Note, you need to download the specific version of third party library and keep that in some local path since it is not available in public repository like Maven Repository.
Let’s see how to install Jakarta Activation jar lib in the local .m2 repository.
Guide to – Manually add or install JARs
To install JAR in local repository Maven provides you the install-file goal option in the maven-install-plugin. The mvn command or syntax to install JAR in local repo is as follows.
mvn install:install-file \ -Dfile=<path-to-file> \ -DgroupId=<group-id> \ -DartifactId=<artifact-id> \ -Dversion=<version> \ -Dpackaging=<packaging> \ -DgeneratePom=true
Let’s see how to run the above command for our example JAR lib. Before you modify or update command specific to your JAR lib, you need to get the following details:
- path-to-file is the path where you kept the third party JAR lib.
- group-id, artifact-id, version details you need to get it from the following dependency info.
For example,
<dependency> <groupId>com.sun.activation</groupId> <artifactId>jakarta.activation</artifactId> <version>2.0.1</version> </dependency>
- packaging is nothing but jar.
After getting the above details, modify the syntax as shown below using your JAR’s specifications. Now, the mvn command should look like below.
mvn install:install-file -Dfile=C:\Users990\Documents\Sneppets\work\jakarta.activation-2.0.1.jar -DgroupId=com.sun.activation -DartifactId=jakarta.activation -Dversion=2.0.1 -Dpackaging=jar -DgeneratePom=true
For instance, try to run the above command, you will see the following response.
> mvn install:install-file -Dfile=C:\Users990\Documents\Sneppets\work\jakarta.activation-2.0.1.jar -DgroupId=com.sun.activation -DartifactId=jakarta.activation -Dversion=2.0.1 -Dpackaging=jar -DgeneratePom=true [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 C:\Users990\Documents\Sneppets\work\jakarta.activation-2.0.1.jar to C:\Users990\.m2\repository\com\sun\activation\jakarta.activation.0.1\jakarta.activation-2.0.1.jar [INFO] Installing C:\Users990\AppData\Local\Temp\mvninstall17675878811172460539.pom to C:\Users990\.m2\repository\com\sun\activation\jakarta.activation.0.1\jakarta.activation-2.0.1.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.482 s [INFO] Finished at: 2021-06-22T09:53:55+05:30 [INFO] ------------------------------------------------------------------------
That’s it. Therefore, the third party JAR lib is added/installed to your local .m2 repository and your Eclipse Maven Project can start using them. This is how you need to manually add JARs to your local repo.
Hope it is helpful 🙂
You’ll also like:
- Java 8 : Find union and intersection of two Lists (ArrayLists)
- Spring Boot App Program Error: Could not find or load main class
- How to copy contents of a List to another List in Java
- Replace element in ArrayList at specific index
- Convert Integer List to int array
- ArrayList removeAll() method not removing elements
- Convert floating point number to fixed point in Python
- What is %matplotlib inline and how to use ?
- Java String substring() example program
- Add python3 kernel to jupyter IPython notebook ?
- Reset jupyter notebook theme to default theme
- How to change the default theme in Jupyter Notebook ?
- To run Jupyter Notebook on Windows from command line
- Run a Jupyter Notebook .ipynb file from terminal or cmd prompt
- Websocket connection closed automatically – keepalive Ping example
- Check if a file or folder exists without getting exceptions ?
- Python program to find the greatest of three numbers
- Putty Fatal Error No supported authentication methods available
- Find which users belongs to a specific group in linux
- Check if Python Object is a Number ?
- Remove non-numeric characters from string in Python
- Convert negative to positive number in Python
- Extract numbers from a string in python
- Program to Check Given Number is Odd or Even