When using the Apache Maven build system, it is common to add dependencies to the pom.xml file. These dependencies are usually stored in a central repository, such as Maven Central or JBoss Repository. However, there are times when you will need to add a dependency that is not available in these repositories.
In this case, you will need to add the dependency to your local Maven repository.
- Open the pom
- xml file in the project’s root directory
- Add the following dependency element to the pom
- xml file: 3
- Save the changes to the pom
- xml file and close it
How to add local jar files to a Maven project? || Managing External Dependencies in Maven? || Maven
How Do I Add Local Jar to Pom?
There are two ways to add a local JAR file to a Maven project:
1. Add the JAR file to your local Maven repository.
2. Specify the path to the JAR file in the
Adding the JAR file to your local Maven repository is the preferred way, because it allows you to share the JAR file with other developers on your team and maintain a central repository of all dependencies used by your project. To add a JAR file to your local Maven repository, use the following command:
mvn install:install-file -Dfile=
-DartifactId=
For example, if you were adding log4j version 1.2.16 to your project, you would use the following command:
mvn install:install-file -Dfile=/Users/jbloggs/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar \ -DgroupId=log4j -DartifactId=log4j -Dversion=1.2.16 -Dpackaging=jar Once you have installed the JAR file in your local Maven repository, you can add it as a dependency in your POM using its group ID, artifact ID and version number:
How Do I Manually Add Dependency in Pom Xml?
Assuming you are using Maven:
In your POM file, under the project root, add a new
Each
It’s generally recommended that you also specify a
How Do I Reference a Local Dependency in Maven?
If you need to reference a local dependency in Maven, you can do so by specifying the file path in your project’s pom.xml file. For example, let’s say you have a jar file called “myjar.jar” that you want to include as a dependency in your project. You would add the following to your pom.xml:
How Do I Add a Dependency to a Jar File?
If you’re using Eclipse, you can add a JAR file to your project by right-clicking on the project in the Package Explorer and choosing Properties. In the Properties window, choose Java Build Path and then the Libraries tab. Click Add External JARs and select the JAR file you want to add.
You can also add a JAR file to your project in NetBeans by right-clicking on the Libraries node of your project in the Projects window and choosing Add Jar/Folder. In the resulting dialog box, navigate to where you have stored the JAR file you want to use and click OK.

Credit: www.baeldung.com
Conclusion
Assuming you have a local jar file that you want to include as a dependency in your project, you would need to do the following:
1. Add the path to your local Maven repository in your pom.xml file:
m2/repository
2. Include the jar as a dependency:
— If using version 2+ of maven –>