How do I add local jar files (not yet part of the Maven repository) directly in my project's library sources?
-
1Hi @Praneel PIDIKITI, Can you please change the accepted answer to the one with the most votes? – null May 06 '17 at 05:51
-
2@nslntmnx That won't be better solution, as all solution have drawbacks https://stackoverflow.com/questions/364114/can-i-add-jars-to-maven-2-build-classpath-without-installing-them – Paul Verest Jul 25 '17 at 14:20
-
2If your libs are updated or extended on occasion see [this answer](https://stackoverflow.com/a/48670812/1744774) to [I want to load all JARs from my libs project folder with maven](https://stackoverflow.com/q/48665906/1744774) for a "pomified" way and such avoiding an additional repo folder and cumbersome cmd lines or `install-file` scripts. – Gerold Broser Feb 07 '18 at 19:45
-
I think adding local jars is at least a "bad smell". Either you must push them in SCM, or others (or the build systems) might not have them locally. This just means possible build failures (and similar troubles). Take the time, push them to the artifact repository used by your team (e.g., as "legacy" libraries), and reference them from that repo in the project. – ltuska Oct 07 '22 at 16:53
35 Answers
You can add local dependencies directly (as mentioned in build maven project with propriatery libraries included) like this:
<dependency>
<groupId>com.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/Name_Your_JAR.jar</systemPath>
</dependency>
Update
In new releases this feature is marked as deprecated but still working and not removed yet ( You just see warning in the log during maven start). An issue is raised at maven group about this https://issues.apache.org/jira/browse/MNG-6523 ( You can participate and describe why this feature is helpful in some cases). I hope this feature remains there!
If you are asking me, as long as the feature is not removed, I use this to make dependency to only one naughty jar file in my project which is not fit in repository. If this feature is removed, well, there are lots of good answers here which I can chose from later!

- 2,714
- 1
- 18
- 29

- 42,517
- 14
- 123
- 173
-
58There are times when you want to specifically test an old jar for example, and I think this answer is a good fit for that. It's the one I needed. Upvoted – John Lockwood Oct 31 '14 at 21:19
-
2**External folder better?** That example `
` suggests a folder within the project. Would it make more sense to keep such jars in a folder external to the project? Sort of like a little pseudo-repository. I assume that Maven pulls a copy of the jar from such an external folder. – Basil Bourque Jun 06 '15 at 21:49 -
44As nice and easy as it looks, this solution has the problem that yourJar.jar will not be included in a WAR file for your app. – Matthias Aug 03 '15 at 20:58
-
1@Matthias why not? He placed it directly in the `/src/main/resources/` folder. That ought to be part of the project. – EpicPandaForce Aug 31 '15 at 10:15
-
@EpicPandaForce It will be included in the WAR under WEB-INF by default, not in the expected WEB-INF/lib directory. – Jeremy Ninnes Dec 05 '15 at 00:06
-
50Above solution doesn't work anymore, it returns: " 'dependencies.dependency.systemPath' for xx.jar should not point at files within the project directory" This has been already dealt in http://stackoverflow.com/questions/10935135/maven-and-adding-jars-to-system-scope – sarah.ferguson Dec 09 '15 at 14:31
-
any idea about how to create executable jar without including external dependencies(library files)? – ROOT Jan 09 '16 at 08:57
-
3This post really helped me packaging a library within a jar using Spring Boot. To be available on the classpath (within the lib folder in the jar), I had to add "lib" as a subfolder:
${project.basedir}/src/main/resources/lib/yourJar.jar . That way, the library was packaged directly in the good destination folder. – dangig Nov 07 '16 at 21:25 -
2This explains why not to use the systemPath, and provides nice solution to automate installing the jar into the local repo: http://stackoverflow.com/questions/10935135/maven-and-adding-jars-to-system-scope – Tao Starbow Dec 08 '16 at 00:06
-
9In this answer, aren't the `artifactId` and `groupId` the wrong way around? – theonlygusti Mar 08 '17 at 08:18
-
5According to Maven docu (https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies): Important note: This is marked deprecated. – agassner Dec 19 '17 at 22:16
-
-
For me it still works. Jar placing - exactly as described, in /resources – user2501323 Feb 18 '20 at 13:22
-
-
-
Is there a best practice for the location of the library? I'd lice to avoid src/main/resources/ – Roberto Petrilli Sep 04 '20 at 16:34
-
2Wonder what's the best way to add multiple jar files to a maven project (speaking of ~50 jar files)? Checked out addjars-maven-plugin but it doesn't work for me in neither intellij nor vscode – Andrei Feb 05 '21 at 22:08
-
-
[`
system`](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies) is deprecated. – Gerold Broser Oct 29 '21 at 16:09
Install the JAR into your local Maven repository (typically .m2
in your home folder) as follows:
mvn install:install-file \
-Dfile=<path-to-file> \
-DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version> \
-Dpackaging=<packaging> \
-DgeneratePom=true
Where each refers to:
<path-to-file>
: the path to the file to load e.g → c:\kaptcha-2.3.jar
<group-id>
: the group that the file should be registered under e.g → com.google.code
<artifact-id>
: the artifact name for the file e.g → kaptcha
<version>
: the version of the file e.g → 2.3
<packaging>
: the packaging of the file e.g. → jar
Reference
- Maven FAQ: I have a jar that I want to put into my local repository. How can I copy it in?
- Maven Install Plugin Usage: The
install:install-file
goal

- 73,784
- 33
- 194
- 347

- 12,675
- 4
- 32
- 46
-
13Instructions to install on my build had everything except the generatePom part. That appears to be crucial. – Jason D Jul 14 '14 at 18:43
-
23The answer doesn't mention a README or that the jars are brought along. However, if the project brings the jars along then you might as well put the repo in the project as mentioned here http://stackoverflow.com/a/36602256/1000011 then you have no need for a README as the project will just work as if the jars were in maven central without any extra manual steps. – opticyclic Jun 27 '16 at 23:34
-
10@opticyclic your comment needs more upvotes, or this answer needs to be edited. It is a recipe for disaster for novices who don't realize that installing to the local Maven repo would not include for everyone else. – Mike S Jul 28 '16 at 18:40
-
1
-
1If there is the pom.xml file available, the command is simpler: mvn install:install-file -Dfile=
-DpomFile= – pkalinow Sep 27 '22 at 11:42(https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html)
Firstly, I would like to give credit for this answer to an anonymous Stack Overflow user - I am pretty sure I've seen a similar answer here before - but now I cannot find it.
The best option for having local JAR files as a dependency is to create a local Maven repository. Such a repository is nothing more than a proper directory structure with pom files in it.
For my example:
I have my master project on ${master_project}
location and subproject1 is on ${master_project}/${subproject1}
.
Then I create a Maven repository in:
${master_project}/local-maven-repo
.
In the pom file in subproject1 located at ${master_project}/${subproject1}/pom.xml
, the repository needs to be specified which would take file path as a URL parameter:
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file:///${project.parent.basedir}/local-maven-repo</url>
</repository>
</repositories>
The dependency can be specified as for any other repository. This makes your pom repository independent. For instance, once the desired JAR is available in Maven central, you just need to delete it from your local repo and it will be pulled from the default repo.
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.servicebinder</artifactId>
<version>0.9.0-SNAPSHOT</version>
</dependency>
The last but not least thing to do is to add the JAR file to local repository using -DlocalRepositoryPath switch like so:
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file \
-Dfile=/some/path/on/my/local/filesystem/felix/servicebinder/target/org.apache.felix.servicebinder-0.9.0-SNAPSHOT.jar \
-DgroupId=org.apache.felix -DartifactId=org.apache.felix.servicebinder \
-Dversion=0.9.0-SNAPSHOT -Dpackaging=jar \
-DlocalRepositoryPath=${master_project}/local-maven-repo
Once the JAR file is installed, your Maven repo can be committed to a code repository, and the whole set-up is system independent. (Working example in GitHub).
I agree that having JARs committed to source code repo is not a good practice, but in real life, quick and dirty solutions are sometimes better than a full blown Nexus repo to host one JAR that you cannot publish.
-
-
6If you want to do this in pom.xml, check out http://www.baeldung.com/install-local-jar-with-maven/ – treehouse Nov 18 '15 at 19:54
-
@Kai Wang This solution works way better! you should maybe add this as an answer. – lockwobr Apr 13 '16 at 16:58
-
You should be using deploy and not install to create your repo correctly. – opticyclic Apr 27 '16 at 04:34
-
Here's a way to build up the local repo: `mvn deploy -DaltDeploymentRepository=releaseRepository::default::file://${project.basedir}/repo` – jcadcell Apr 25 '17 at 02:32
-
I tried that on a web project; it compiles the sources and packages the war with no errors, but the jar is not included inside the war. – Haroldo_OK Sep 14 '17 at 16:59
-
Would this work with Bamboo Continuous Integration (CI)? I see how it would work on my workstation, wondering if it would work on the deployment (Bamboo) server, if the install-file commands have not been run there? – Wallace Howery Mar 06 '18 at 23:04
-
15Since `${project.parent.basedir}` doesn't seem to resolve to anything nowadays I used `${project.basedir}/..` and worked perfectly. – The Impaler Nov 02 '18 at 16:10
-
I think this approach is superior, because it creates a reproducible build if you commit the artifact. – Wouter Lievens May 23 '19 at 08:55
-
2The stackoverflow answer that could not be found by OP is probably here: https://stackoverflow.com/a/19226672/2364405 – Mitch Talmadge Aug 18 '19 at 22:22
-
2A tip: please check $HOME/.m2/settings.xml , avoid "local-maven-repo" is mirrored by settings/mirrors/mirror `
* ` . – btpka3 Dec 12 '19 at 03:34 -
@jj-roman very helpful, please add README (the explanation you have put here) to the github project. – 2sb Mar 15 '20 at 18:09
-
Re "_The best option for having local JAR files as a dependency is to create a local Maven repository._" – Why create another one if there is already one by default: `~/.m2/repository`? Re "_Such a repository is nothing more than a proper directory structure with pom files in it._" – This isn't true. There's much more in a Maven repo than just POMs: metadata, hashes, ZIPs and of course JARs/WARs/EARs/etc. which are what all this is about. – Gerold Broser Oct 29 '21 at 16:18
-
This did not work for me. I had to replace the repository creation command with the deploy command that is specified in Vinay Veluri's answer. That way the pom file will be created correctly in the local repository. – BlakeTNC Feb 14 '23 at 18:39
Create a new folder, let's say local-maven-repo
at the root of your Maven project.
Just add a local repo inside your <project>
of your pom.xml
:
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file:///${project.basedir}/local-maven-repo</url>
</repository>
</repositories>
Then for each external jar you want to install, go at the root of your project and execute:
mvn deploy:deploy-file -DgroupId=[GROUP] -DartifactId=[ARTIFACT] -Dversion=[VERS] -Durl=file:./local-maven-repo/ -DrepositoryId=local-maven-repo -DupdateReleaseInfo=true -Dfile=[FILE_PATH]

- 6,671
- 5
- 32
- 56

- 22,041
- 18
- 107
- 163
-
26This is the only correct answer on here as it will create your repo correctly when using deploy. – opticyclic Apr 27 '16 at 04:33
-
Would this approach work if the code is deployed using a CI build server? It looks like automated builds would not have access to the dependency. – Wallace Howery Mar 08 '18 at 22:13
-
2@user2748659 yes if in your CI build servers the folder `local-maven-repo` is included (as a child in this example) in your source folder – Anthony O. Mar 09 '18 at 15:15
-
4This answer is what worked for me. For a shared project, having the repo in the project directory and added to version control makes sure that anyone who checks out the project will not have missing dependencies. If you have a lot of dependencies, then a shared, remote repo is probably a better solution, otherwise keeping the repo in the project's directory is perfectly fine. – Aquarelle May 05 '18 at 04:32
-
How would you then import this library into your project? I did this command: `mvn deploy:deploy-file -DgroupId=com.yahoo.egads -DartifactId=egads -Dversion=0.4.0 -Durl=file:./local-maven-repo/ -DrepositoryId=local-maven-repo -DupdateReleaseInfo=true -Dfile=[MyJarFilePath]` and am trying to import like this: `import com.yahoo.egads.[package]` but it says none of these packages exist. I run my project with `./mvnw` – Ryan Fasching Aug 15 '18 at 01:21
-
4
-
2@RyanFasching yes you still have to add the dependency to your dependencies – Anthony O. Aug 27 '18 at 14:04
-
4Note that to do this you may need to add -Dpackaging=jar. Otherwise you get "artifact info is incomplete or invalid: packaging is missing". – Woodchuck Mar 18 '19 at 01:50
-
1That only works on a UNIX platform. On Windows, the file://C:\.../libs is mangled. – TimeHorse Apr 18 '22 at 18:56
-
1Note that you will still need to add a dependency for the jar. Use the group id, artifact id, and version number that you used in the deploy command. Note that you can make up any group id, artifact id, and version number you wish, as long as they match each other in the deploy command and in the pom dependency section. (This answer worked well for me.) – BlakeTNC Feb 14 '23 at 18:35
I'd like such solution - use maven-install-plugin
in pom file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>lib/yourJar.jar</file>
<groupId>com.somegroup.id</groupId>
<artifactId>artefact-id</artifactId>
<version>x.y.z</version>
<packaging>jar</packaging>
</configuration>
</execution>
</executions>
</plugin>
In this case you can perform mvn initialize
and jar will be installed in local maven repo. Now this jar is available during any maven step on this machine (do not forget to include this dependency as any other maven dependency in pom with <dependency></dependency>
tag). It is also possible to bind jar install not to initialize
step, but any other step you like.

- 4,081
- 10
- 26
- 36

- 3,048
- 8
- 39
- 55
-
4This works well for me, but only if I run `mvn initialize` before `mvn package`: I cannot `mvn initialize package` or else it tries to download the JAR from the central repo. Why is this? I thought it would run this goals/phases in order. – DavidS Jan 17 '17 at 20:31
-
1Actually, they should be run in order. Take a look at the list of default lifecycle: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html You can use another step to bind. – sphinks Jan 18 '17 at 06:47
-
2I tried every method, but in the end I had to resort to this solution. The main reason is, I wanted to be able to locally build the packages in offline mode. If I declared it as a dependency with a locally defined repository, this was always considered as just another online repo and the maven build complained about not fining the artifact. This solution works fine for every case. – Mauli Dec 04 '17 at 11:27
-
2I think is better to use **clean phase** because initialize will be executed each time when we use mvn package when Its unnecessary. Finally if we only need generate the jar/war we can use directly **mvn clean package**. – Deoxyseia Feb 03 '18 at 00:07
-
1"_It is also possible to bind jar install not to initialize step, but any other step you like._" is not necessarily true. If the dependency isn't in the repo yet and a phase is used that comes after a phase that resolves dependencies (e.g. `compile`) the build will fail. – Gerold Broser Feb 07 '18 at 19:41
-
GOTCHA! Putting flags in `configurations` instead of in `mvn install-file...` is what I needed – testing_22 May 22 '22 at 15:19
The really quick and dirty way is to point to a local file, please note "system" is deprecated by now:
<dependency>
<groupId>com.sample</groupId>
<artifactId>samplifact</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>C:\DEV\myfunnylib\yourJar.jar</systemPath>
</dependency>
However this will only live on your machine (obviously), for sharing it usually makes sense to use a proper m2 archive (nexus/artifactory) or if you do not have any of these or don't want to set one up a local maven structured archive and configure a "repository" in your pom:
local:
<repositories>
<repository>
<id>my-local-repo</id>
<url>file://C:/DEV//mymvnrepo</url>
</repository>
</repositories>
remote:
<repositories>
<repository>
<id>my-remote-repo</id>
<url>http://192.168.0.1/whatever/mavenserver/youwant/repo</url>
</repository>
</repositories>
for this solution, a relative path is also possible using the basedir variable:
<url>file:${basedir}</url>

- 3,593
- 30
- 34
-
For local repository URLs, can they be relative or must they be absolute? – Dragas Oct 08 '18 at 07:20
-
-
1Yeah, apparently you need to use `
file:${basedir} ` as base url instead. – Dragas Oct 08 '18 at 08:30 -
[`
system`](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies) is deprecated. – Gerold Broser Oct 29 '21 at 16:04 -
<dependency>
<groupId>group id name</groupId>
<artifactId>artifact name</artifactId>
<version>version number</version>
<scope>system</scope>
<systemPath>jar location</systemPath>
</dependency>

- 55,661
- 15
- 90
- 140

- 1,757
- 4
- 34
- 60
-
7[`
system`](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies) is deprecated now. – Gerold Broser Feb 07 '18 at 19:36 -
-
2@MasterJoe2 As also mentioned in [the accepted answer](https://stackoverflow.com/a/4955695/1744774) [`install:install-file`](https://maven.apache.org/plugins/maven-install-plugin/usage.html#The_install:install-file_goal) the artifact to the local repo and use it as a "normal" dependency (with default scope `compile`) or use an [in-project repository solution](https://stackoverflow.com/a/7623805/1744774). – Gerold Broser May 10 '19 at 08:33
Important part in dependency is: ${pom.basedir} (instead of just ${basedir})
<dependency>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/src/lib/example.jar</systemPath>
</dependency>

- 357
- 2
- 7
-
[`
system`](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies) is deprecated. – Gerold Broser Oct 29 '21 at 15:58
Add your own local JAR in POM file and use that in maven build.
mvn install:install-file -Dfile=path-to-jar -DgroupId=owngroupid -DartifactId=ownartifactid -Dversion=ownversion -Dpackaging=jar
For example:
mvn install:install-file -Dfile=path-to-jar -DgroupId=com.decompiler -DartifactId=jd-core-java -Dversion=1.2 -Dpackaging=jar
Then add it to the POM like this:

- 3,841
- 12
- 44
- 71

- 209
- 2
- 4
-
I get an error Failed to install artifact (access denied). How can I solve this? @Aurasphere – Ramzah Rehman Aug 04 '17 at 06:35
-
1@RamzahRehman try opening the command prompt with admi privileges by right clicking it and then choosing "Run as administrator" – Aurasphere Aug 04 '17 at 07:44
Step 1: Configure the maven-install-plugin
with the goal install-file
in your pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-external-non-maven-jar-MWS-Client-into-local-maven-repo</id>
<phase>clean</phase>
<configuration>
<repositoryLayout>default</repositoryLayout>
<groupId>com.amazonservices.mws</groupId>
<artifactId>mws-client</artifactId>
<version>1.0</version>
<file>${project.basedir}/lib/MWSClientJavaRuntime-1.0.jar</file>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
Make sure to edit the file
path based on your actual file path (recommended is to place these external non-maven jars inside some folder, let's say lib
, and place this lib
folder inside your project so as to use project-specific relative path and avoid adding system specific absolute path.
If you have multiple external jars, just repeat the <execution>
for other jars within the same maven-install-plugin
.
Step 2: Once you have configured the maven-install-plugin
as shown above in your pom.xml
file, you have to use these jars in your pom.xml
as usual:
<dependency>
<groupId>com.amazonservices.mws</groupId>
<artifactId>mws-client</artifactId>
<version>1.0</version>
</dependency>
Note that the maven-install-plugin
only copies your external jars to your local .m2
maven repository. That's it. It doesn't automatically include these jars as maven dependencies to your project.
It's a minor point, but sometimes easy to miss.

- 33,847
- 91
- 226
- 299
-
There is no `
clean` if you run e.g. `mvn compile` and if there wasn't a `mvn clean` before the build will fail. – Gerold Broser Oct 29 '21 at 16:02
One way is to upload it to your own Maven repository manager (such as Nexus). It's good practice to have an own repository manager anyway.
Another nice way I've recently seen is to include the Maven Install Plugin in your build lifecycle: You declare in the POM to install the files to the local repository. It's a little but small overhead and no manual step involved.
http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html
-
4End up with switching to gradle. It doesn't work If the local jar is defined as dependencies, maven will not execute plugins before resolving the dependencies, a manual installation is unavoidable. found a disscussion about this situation: http://stackoverflow.com/questions/5951999/is-there-are-way-to-install-maven-dependencies-before-maven-attempts-to-resolve – xinthink Mar 15 '15 at 16:11
Another interesting case is when you want to have in your project private maven jars. You may want to keep the capabilities of Maven to resolve transitive dependencies. The solution is fairly easy.
- Create a folder libs in your project
Add the following lines in your pom.xml file
<properties><local.repository.folder>${pom.basedir}/libs/</local.repository.folder> </properties> <repositories> <repository> <id>local-maven-repository</id> <url>file://${local.repository.folder}</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
Open the .m2/repository folder and copy the directory structure of the project you want to import into the libs folder.
E.g. suppose you want to import the dependency
<dependency>
<groupId>com.mycompany.myproject</groupId>
<artifactId>myproject</artifactId>
<version>1.2.3</version>
</dependency>
Just go on .m2/repository and you will see the following folder
com/mycompany/myproject/1.2.3
Copy everything in your libs folder (again, including the folders under .m2/repository) and you are done.

- 9,401
- 7
- 53
- 76

- 17,172
- 23
- 113
- 157
Of course you can add jars to that folder. But maybe it does not what you want to achieve...
If you need these jars for compilation, check this related question: Can I add jars to maven 2 build classpath without installing them?
Also, before anyone suggests it, do NOT use the system scope.

- 1
- 1

- 14,632
- 7
- 51
- 70
Add local jar
libraries, their sources
and javadoc
to a Maven project
If you have pre-compiled jar
files with libraries, their sources
and javadoc
, then you can install
them to your local Maven repository like this:
mvn install:install-file -Dfile=awesomeapp-1.0.1.jar \ -DpomFile=awesomeapp-1.0.1.pom \ -Dsources=awesomeapp-1.0.1-sources.jar \ -Djavadoc=awesomeapp-1.0.1-javadoc.jar \ -DgroupId=com.example \ -DartifactId=awesomeapp \ -Dversion=1.0.1 \ -Dpackaging=jar
Then in your project you can use this libraries:
<!-- com.example -->
<dependency>
<groupId>com.example</groupId>
<artifactId>awesomeapp</artifactId>
<version>1.0.1</version>
</dependency>
See: maven-install-plugin usage.
Or you can build
these libraries yourself with their sources
and javadoc
using maven-source-plugin and maven-javadoc-plugin, and then install
them.
Example project: library
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<url>https://example.com/awesomeapp</url>
<groupId>com.example</groupId>
<artifactId>awesomeapp</artifactId>
<name>awesomeapp</name>
<version>1.0.1</version>
<packaging>jar</packaging>
<properties>
<java.version>12</java.version>
</properties>
<build>
<finalName>awesomeapp</finalName>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals><goal>jar</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals><goal>jar</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Execute maven install
goal:
mvn install
Check your local Maven repository:
~/.m2/repository/com/example/awesomeapp/1.0.1/
├─ _remote.repositories
├─ awesomeapp-1.0.1.jar
├─ awesomeapp-1.0.1.pom
├─ awesomeapp-1.0.1-javadoc.jar
└─ awesomeapp-1.0.1-sources.jar
Then you can use this library:
<!-- com.example -->
<dependency>
<groupId>com.example</groupId>
<artifactId>awesomeapp</artifactId>
<version>1.0.1</version>
</dependency>
-
If you are using Windows's powershell, you will need to escape the `.` character not part of a file by enclosing the string between quotation marks. For instance : `-DgroupId="org.primefaces"` `-Dversion="12.0.3" ` – Pierre C Mar 14 '23 at 23:33
command line :
mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code
-DartifactId=kaptcha -Dversion={version} -Dpackaging=jar

- 131
- 1
- 9
I think a better solution for this problem is to use maven-install-plugin to automatically install the files at install time. This is how I set it up for my project.
First, add the path (where you store the local .jars) as a property.
<properties>
<local.sdk>/path/to/jar</local.sdk>
</properties>
Then, under plugins
add a plugin to install the jars when compiling.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>1</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>com.local.jar</groupId>
<artifactId>appengine-api</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>${local.sdk}/lib/impl/appengine-api.jar</file>
</configuration>
</execution>
<execution>
<id>appengine-api-stubs</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>com.local.jar</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>${local.sdk}/lib/impl/appengine-api-stubs.jar</file>
</configuration>
</execution>
</executions>
</plugin>
Finally, in dependencies, you can add the jars
<dependency>
<groupId>com.local.jar</groupId>
<artifactId>appengine-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.local.jar</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
By Setting up your project like this, the project will continue to build even when you take it to another computer (given that it has all the jar files in the path specified by the property local.sdk
).
For groupId
use a unique name just to make sure that there are no conflicts.
Now when you mvn install
or mvn test
local jars will be added automatically.

- 4,769
- 3
- 34
- 39
This is a short syntax for newer versions:
mvn install:install-file -Dfile=<path-to-file>
It works when the JAR was built by Apache Maven - the most common case. Then it'll contain a pom.xml in a subfolder of the META-INF directory, which will be read by default.
Source: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

- 1,552
- 1
- 19
- 23
Not an answer to the original question, however it might be useful for someone
There is no proper way to add multiple jar libraries from the folder using Maven. If there are only few dependencies, it is probably easier to configure maven-install-plugin
as mentioned in the answers above.
However for my particular case, I had a lib
folder with more than 100 proprietary jar files which I had to add somehow. And for me it was much easier for me to convert my Maven
project to Gradle
.
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
flatDir {
dirs 'libs' // local libs folder
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation 'io.grpc:grpc-netty-shaded:1.29.0'
implementation 'io.grpc:grpc-protobuf:1.29.0'
implementation 'io.grpc:grpc-stub:1.29.0' // dependecies from maven central
implementation name: 'akka-actor_2.12-2.6.1' // dependecies from lib folder
implementation name: 'akka-protobuf-v3_2.12-2.6.1'
implementation name: 'akka-stream_2.12-2.6.1'
}

- 5,831
- 3
- 35
- 45
I want to share a code where you can upload a folder full of jars. It's useful when a provider doesn't have a public repository and you need to add lots of libraries manually. I've decided to build a .bat instead of call directly to maven because It could be Out of Memory errors. It was prepared for a windows environment but is easy to adapt it to linux OS:
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
public class CreateMavenRepoApp {
private static final String OCB_PLUGIN_FOLDER = "C://your_folder_with_jars";
public static void main(String[] args) throws IOException {
File directory = new File();
//get all the files from a directory
PrintWriter writer = new PrintWriter("update_repo_maven.bat", "UTF-8");
writer.println("rem "+ new Date());
File[] fList = directory.listFiles();
for (File file : fList){
if (file.isFile()){
String absolutePath = file.getAbsolutePath() ;
Manifest m = new JarFile(absolutePath).getManifest();
Attributes attributes = m.getMainAttributes();
String symbolicName = attributes.getValue("Bundle-SymbolicName");
if(symbolicName!=null &&symbolicName.contains("com.yourCompany.yourProject")) {
String[] parts =symbolicName.split("\\.");
String artifactId = parts[parts.length-1];
String groupId = symbolicName.substring(0,symbolicName.length()-artifactId.length()-1);
String version = attributes.getValue("Bundle-Version");
String mavenLine= "call mvn org.apache.maven.plugins:maven-install-plugin:2.5.1:install-file -Dfile="+ absolutePath+" -DgroupId="+ groupId+" -DartifactId="+ artifactId+" -Dversion="+ version+" -Dpackaging=jar ";
writer.println(mavenLine);
}
}
}
writer.close();
}
}
After run this main from any IDE, run the update_repo_maven.bat.

- 59
- 1
-
Your code `String symbolicName = attributes.getValue("Bundle-SymbolicName"); if(symbolicName!=null &&symbolicName.contains("com.yourCompany.yourProject"))` seems to indicate that only *custom* jars will be supported. That's not what we need: instead a bunch of third party jars. Do you have suggestions how to install *any* jar this way? – WestCoastProjects Nov 27 '16 at 20:03
-
Also take a look at...
<scope>compile</scope>
Maven Dependencies. This is the default but I've found in some cases explicitly setting that scope also Maven to find local libraries in the local repository.

- 11,672
- 5
- 42
- 59
- Create a local Maven repository directory, Your project root should look something like this to start with:
yourproject
+- pom.xml
+- src
- Add a standard Maven repository directory called repo for the group com.example and version 1.0:
yourproject
+- pom.xml
+- src
+- repo
- Deploy the Artifact Into the Repo, Maven can deploy the artifact for you using the mvn deploy:deploy-file goal:
mvn deploy:deploy-file -Durl=file:///pathtoyour/repo -Dfile=your.jar -DgroupId=your.group.id -DartifactId=yourid -Dpackaging=jar -Dversion=1.0
- install pom file corresponding to your jar so that your project can find jar during maven build from local repo:
mvn install:install-file -Dfile=/path-to-your-jar-1.0.jar -DpomFile=/path-to-your-pom-1.0.pom
- add repo in your pom file:
<repositories>
<!--other repositories if any-->
<repository>
<id>project.local</id>
<name>project</name>
<url>file:${project.basedir}/repo</url>
</repository>
</repositories>
- add the dependency in your pom:
<dependency>
<groupId>com.groupid</groupId>
<artifactId>myid</artifactId>
<version>1.0</version>
</dependency>

- 1,959
- 19
- 15
To install third party jar, Please call the command like below
mvn install:install-file -DgroupId= -DartifactId= -Dversion= -Dpackaging=jar -Dfile=path

- 21,519
- 75
- 241
- 416

- 2,485
- 3
- 22
- 27
For some reason, in the web application I'm giving maintenance to, neither Alireza Fattahi's solution nor JJ Roman's solution worked correctly. In both cases, the compilation goes okay (it sees the jar), but the packaging fails to include the jar inside the war.
The only way I managed to make it work was by putting the jar on /src/main/webapp/WEB-INF/lib/
and then combining it with either Fattahis's or Roman's solution.

- 6,612
- 3
- 43
- 80
- Download jar file
- copy jar file to the project folder
- get inteliJ idea Maven command area
- type below command
mvn install:install-file -Dfile=YOUR_JAR_FILE_LOCATION*JARNAME.jar -DgroupId=org.primefaces.themes -DartifactId=iMetro -Dversion=1.0.1 -Dpackaging=jar*
example :
mvn install:install-file -Dfile=C:\Users\ranushka.l\Desktop\test\spring-web-1.0.2.jar -DgroupId=org.primefaces.themes -DartifactId=iMetro -Dversion=1.0.1 -Dpackaging=jar

- 494
- 5
- 6
Note that it is NOT necessarily a good idea to use a local repo. If this project is shared with others then everyone else will have problems and questions when it doesn't work, and the jar won't be available even in your source control system!
Although the shared repo is the best answer, if you cannot do this for some reason then embedding the jar is better than a local repo. Local-only repo contents can cause lots of problems, especially over time.
-
1if you add the jars in the source control system the libraries will always be available together with the source. No source, No libraries. With maven instead the source might be ok but the repository unavailable. – sarah.ferguson Dec 09 '15 at 14:34
-
@Frank... any idea about how to create executable jar without including external dependencies(library files)? – ROOT Jan 09 '16 at 08:56
-
For someone new to maven, and looking for an answer to the original question, what does "embedding the jar" mean? – cdock Feb 11 '17 at 16:09
On your local repository you can install your jar by issuing the commands
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
Follow this useful link to do the same from mkyoung's website. You can also check maven guide for the same

- 1,091
- 16
- 23
- mvn install
You can write code below in command line or if you're using eclipse builtin maven right click on project -> Run As -> run configurations... -> in left panel right click on Maven Build -> new configuration -> write the code in Goals & in base directory :${project_loc:NameOfYourProject} -> Run
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
-DgeneratePom=true
Where each refers to:
< path-to-file >: the path to the file to load e.g -> c:\kaptcha-2.3.jar
< group-id >: the group that the file should be registered under e.g -> com.google.code
< artifact-id >: the artifact name for the file e.g -> kaptcha
< version >: the version of the file e.g -> 2.3
< packaging >: the packaging of the file e.g. -> jar
2.After installed, just declares jar in pom.xml.
<dependency>
<groupId>com.google.code</groupId>
<artifactId>kaptcha</artifactId>
<version>2.3</version>
</dependency>

- 1,255
- 11
- 18
Perhaps someone will be interested in: https://github.com/Limraj/maven-artifact-generator
Console program to generate maven artifacts in the local repository, and configure dependencies for pom.xml, based on the path to the jars. You can do this for one file, but it's most useful if you have multiple jar files.
path jars: java -jar maven-artifact-generator-X.X.X.jar -p path_to_jars -g com.test -V 1.2.3 -P jar
jar: java -jar maven-artifact-generator-X.X.X.jar -f file_jar -g com.test -V 1.2.3 -P jar
This will generate an artifact in the local maven repository, and generate dependecies for pom.xml in gen.log. ArtifactId is the name of the jar file.
Requires an installed maven. Testing on widnows 7 and macOS X (unix/linux).

- 140
- 8
I had the same error for a set of dependencies in my pom.xml turns out the versions of the dependencies was not specified in the pom.xml and was mentioned in the parent repository. For some reason the version details was not syncing with this repo. Hence i manually entered the versions using the tag and it worked like a charm. Little bit of time needed to look up the versions in the parent and specify here. But this can be done just for the jars that are showing the artifactid error and it works. Hope this helps someone.

- 11
- 2
In Apache Maven 3.5.4, I had to add double quotation. Without double quotation it wasn't worked for me.
example: mvn install:install-file "-Dfile=location to the jar file" "-DgroupId=group id" "-DartifactId=artifact id" "-Dversion=version" "-Dpackaging=package type"

- 354
- 6
- 15
My shaded jar file did not contain the third-party library using AlirezaFattahi's solution. however, I remeber that it was working once I had tried it for the same project last time. So, I tried my own solution:
- mkdir the project's path under .m2/repositories directory (similar to other maven dependencies directory at that directory)
- put the third-party jar file in it.
- add the dependency as like as the libraries on a maven repository.
Finally, It worked for me. :)

- 881
- 1
- 9
- 20
In my case, it turned out my existing maven build was already installing the jar file in question into my local repository, but I wasn't seeing the expected results because local builds produce artifacts with suffix '-SNAPSHOT' in them. The very simple solution for me was to update the pom.xml file of the projects that make use of the locally build jar file, to match the name.
<myproject.foo.version>1.88-SNAPSHOT</myproject.foo.version>
instead of
<myproject.foo.version>1.88</myproject.foo.version>
The takeaway is that if it seems like your jar file should already be in your local .m2/maven repo, it very well may be, and you just need to update your dependency accordingly.

- 2,043
- 20
- 17
If you are a Spring developer, you will find that the JAR you produce from a Spring Boot build will not work as a dependency JAR in another build. Check if your POM has this:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
And also check, if you run mvn package
whether you see a .jar.original file as well as the .jar in the target/
directory. If so, you need to use that .jar.original file for any local development (putting it into a lib/ or something.)
You can work around this of course; see the original post which references the plugin manual at Spring. I think, you would need the <configuration> <attach>false</attach> <configuration>
and then you would have to deploy and Maven should use the .jar.original file. I have not tried this myself so do let me know!

- 459
- 4
- 4
a pom repository pointing to ${project.directory}/repo/
or a file:// uri can work with source-resident jarfiles for a trivial project's deps frozen in time. these will not leak into the system ~/.m2 repo but will affect the choice of maven version selection against the (typically more recent) top-level when unspecified.
for existing deps being bundled at distribution-time similar to shade but more direct, if you can run with "target" being your favorite structure or maven's default:
-cp "$PWD/target/classes:$PWD/target/lib/*" pkg.random.ClassWithMain
then
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

- 23
- 5