How to include custom library into maven local repository?
For Java libraries that are not available in the Maven Central or other Maven repositories, we need to install it into our Maven Local repository in order to use it as a project dependencies.
You may interest at this How to add Oracle JDBC driver in your Maven local repository
In this tutorial, we will show you how to install the kaptcha
jar into our Maven local repository.
1. Kaptcha
For example, kaptcha, a popular third party Java library, which is generating captcha
image to stop spam, but it’s not available in the Maven center repository.
Now, the
kaptcha
is available in the Maven Central Repository. It is fine, even it is in the Maven Central, we still can install the Kaptcha JAR file manually into our Maven local repository.
2. mvn install
Download the kaptcha, extract it and copy the kaptcha-${version}.jar
to somewhere else, for example, C drive, and run this command:
$ mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code
-DartifactId=kaptcha -Dversion={version} -Dpackaging=jar
For example:
> mvn install:install-file -Dfile=c:\kaptcha-2.3.jar -DgroupId=com.google.code
-DartifactId=kaptcha -Dversion=2.3 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'install'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [install:install-file] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [install:install-file]
[INFO] Installing c:\kaptcha-2.3.jar to
D:\maven_repo\com\google\code\kaptcha\2.3\kaptcha-2.3.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Tue May 12 13:41:42 SGT 2009
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------
Done, the kaptcha jar is installed (copied) into our Maven local repository.
3. pom.xml
After installed, just declares the kaptcha
dependency as usual.
<dependency>
<groupId>com.google.code</groupId>
<artifactId>kaptcha</artifactId>
<version>2.3</version>
</dependency>
4. Alternative Solution
Forget about the ‘mvn install`, we also can download the .jar
and tell the project to find the .jar
in the system path like this:
<dependency>
<groupId>com.google.code</groupId>
<artifactId>kaptcha</artifactId>
<version>2.3</version>
<scope>system</scope>
<systemPath>d:/projects/kaptcha.jar</systemPath>
</dependency>
<dependency>
<groupId>com.google.code</groupId>
<artifactId>kaptcha</artifactId>
<version>2.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/kaptcha.jar</systemPath>
</dependency>
Hi,
I have a spring boot app say A, which I am using in other spring boot app say B as Maven dependency, the above process is working, but when I modify anything in app A manually I have to run mvn package and by above process I’ve to include the jar in local repo, is there any automated process, if I modify app A automatically it gets updated in Maven local repo.
Try create a Maven multi module project
https://www.mkyong.com/maven/maven-how-to-create-a-multi-module-project/
The problem I’m facing after this is the following error:
[WARNING] The POM for pipapo.jar is missing, no dependency information availalable
Obviously there is no POM because the other project had nothing to do with maven. So how do I get rid of these errors?
Maven install file should generate the pom file automatically. Try upgrade Maven to the latest 3.6, and test it again.
Thank you! So helpful!!!
Hi,
i just have file pom.xml onlinux
viettelsecurity
viettelsecurity
2.0
system
${project.basedir}/lib/viettelsecurity2.0.jar
but output show
[WARNING] ‘dependencies.dependency.systemPath’ for viettelsecurity:viettelsecurity:jar should not point at files within the project directory, ${project.basedir}/lib/viettelsecurity2.0.jar will be unresolvable by dependent projects @ line 119, column 16
so local lib can not import my file war
can you help me fix this? thanks
I had to copy my custom jar at “${project.basedir}/src/main/webapp/WEB-INF/lib” & specify that as “systemPath” in pom.xml in order to get this jar included in my war file which is created by mvn install. This was not done automatically if my custom jar is located somewhere else.
It doesn’t work for me and sorry for this log errors
C:\PostEvent\workspace\geostatus>mvn install:install-file -Dfile=C:/PostEvent/workspace/geostatus/sr
c/main/resources/libxldkkdkdkkd -DgroupeId=ebx -DartifactId=ebx -Dversion=5.9.3 -Dpackaging=jar -Dge
neratePom=truemvn install:install-file -Dfile=C:/PostEvent/workspace/geostatus/src/main/resources/li
b -DgroupeId=ebx -DartifactId=ebx -Dversion=5.9.3 -Dpackaging=jarmvn install:install-file -Dfile=C:/
PostEvent/workspace/geostatus/src/main/resources/lib/ebx.jar -DgroupeId=ebx -DartifactId=ebx -Dversi
on=5.9.3 -Dpackaging=jar
[INFO] Scanning for projects…
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-eclips
e-plugin/2.9/maven-eclipse-plugin-2.9.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-eclipse-plugin:2.9
: Plugin org.apache.maven.plugins:maven-eclipse-plugin:2.9 or one of its dependencies could not be r
esolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-eclipse-plugin:jar:2.
9
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-shade-
plugin/1.6/maven-shade-plugin-1.6.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-shade-plugin:1.6:
Plugin org.apache.maven.plugins:maven-shade-plugin:1.6 or one of its dependencies could not be resol
ved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-shade-plugin:jar:1.6
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-war-pl
ugin/2.1.1/maven-war-plugin-2.1.1.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-war-plugin:2.1.1:
Plugin org.apache.maven.plugins:maven-war-plugin:2.1.1 or one of its dependencies could not be resol
ved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-war-plugin:jar:2.1.1
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-
plugin/2.5/maven-clean-plugin-2.5.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-clean-plugin:2.5:
Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resol
ved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resour
ces-plugin/2.6/maven-resources-plugin-2.6.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-resources-plugin:2
.6: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not
be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:
jar:2.6
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefi
re-plugin/2.12.4/maven-surefire-plugin-2.12.4.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-surefire-plugin:2.
12.4: Plugin org.apache.maven.plugins:maven-surefire-plugin:2.12.4 or one of its dependencies could
not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-surefire-plug
in:jar:2.12.4
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-instal
l-plugin/2.4/maven-install-plugin-2.4.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-install-plugin:2.4
: Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be r
esolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-install-plugin:jar:2.
4
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-deploy
-plugin/2.7/maven-deploy-plugin-2.7.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-deploy-plugin:2.7:
Plugin org.apache.maven.plugins:maven-deploy-plugin:2.7 or one of its dependencies could not be res
olved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-deploy-plugin:jar:2.7
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-site-p
lugin/3.3/maven-site-plugin-3.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-site-plugin:3.3: P
lugin org.apache.maven.plugins:maven-site-plugin:3.3 or one of its dependencies could not be resolve
d: Failed to read artifact descriptor for org.apache.maven.plugins:maven-site-plugin:jar:3.3
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-antrun
-plugin/1.3/maven-antrun-plugin-1.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-antrun-plugin:1.3:
Plugin org.apache.maven.plugins:maven-antrun-plugin:1.3 or one of its dependencies could not be res
olved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-antrun-plugin:jar:1.3
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-assemb
ly-plugin/2.2-beta-5/maven-assembly-plugin-2.2-beta-5.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-assembly-plugin:2.
2-beta-5: Plugin org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5 or one of its dependencie
s could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-assem
bly-plugin:jar:2.2-beta-5
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-depend
ency-plugin/2.8/maven-dependency-plugin-2.8.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-dependency-plugin:
2.8: Plugin org.apache.maven.plugins:maven-dependency-plugin:2.8 or one of its dependencies could no
t be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-dependency-plug
in:jar:2.8
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-releas
e-plugin/2.5.3/maven-release-plugin-2.5.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-release-plugin:2.5
.3: Plugin org.apache.maven.plugins:maven-release-plugin:2.5.3 or one of its dependencies could not
be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-release-plugin:ja
r:2.5.3
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metada
ta.xml
[WARNING] Could not transfer metadata org.apache.maven.plugins/maven-metadata.xml from/to central (h
ttps://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/15
1.101.16.215] failed: Connection refused: connect
[WARNING] Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/to central (https://
repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.1
6.215] failed: Connection refused: connect
[WARNING] Failure to transfer org.apache.maven.plugins/maven-metadata.xml from https://repo.maven.ap
ache.org/maven2 was cached in the local repository, resolution will not be reattempted until the upd
ate interval of central has elapsed or updates are forced. Original error: Could not transfer metada
ta org.apache.maven.plugins/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2
): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.16.215] failed: Connection re
fused: connect
[WARNING] Failure to transfer org.codehaus.mojo/maven-metadata.xml from https://repo.maven.apache.or
g/maven2 was cached in the local repository, resolution will not be reattempted until the update int
erval of central has elapsed or updates are forced. Original error: Could not transfer metadata org.
codehaus.mojo/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2): Connect to
repo.maven.apache.org:443 [repo.maven.apache.org/151.101.16.215] failed: Connection refused: connect
[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 27.031 s
[INFO] Finished at: 2019-06-14T18:23:34+02:00
[INFO] ————————————————————————
[ERROR] No plugin found for prefix ‘install’ in the current project and in the plugin groups [org.ap
ache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\bachiramazig
h.badjad\.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following arti
cles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException
Thank you, It worked for me 🙂
Hi, Mkyong. I would like to know if you have an example of add external JAR to the maven project but taking into account that this JAR has a NATIVE LIBRARY dependency. As the case of include OpenCV Library in a Maven Project.
it worked.. thanks a lot !
thank you. what i needed and simple.
Thank you, It worked for me. It saved my time
Hi mkyong,
I use this article for a longe time, it is very usefull. But I have a situation: need to install this http://mvnrepository.com/artifact/commons-cli/commons-cli/1.0 manually, but the maven refuse to install. How to install?
worked perfectly for me
Thanks for the post. I’m trying this but looks like it did
not work for me.
I’m creating a library a project and copied the jar to
c:mylibtest-automation-library-0.0.1-SNAPSHOT.jar
I’m running the test scripts through Jenkins.
In the Jenkins job of test scripts, I included the following
pre-build step install the library:
install:install-file
-Dfile=c:mylibtest-automation-library-0.0.1-SNAPSHOT.jar
-DgroupId=com.mycompany.taf -DartifactId=test-automation-library
-Dversion=0.0.1 -Dpackaging=jar
This installs the jar to maven local repository (where are
the scripts are supposed to run) and build is successful
in the POM file of the test-scripts, I included the
following dependency for the above library:
com.mycompany.taf
test-automation-library
0.0.1-SNAPSHOT
If I do maven install through Jenkins, I’m hitting the
following error:
[INFO]
————————————————————————
[WARNING] The POM for
com.mycompany.taf:test-automation-library:jar:0.0.1-SNAPSHOT is missing, no
dependency information available
[INFO] ————————————————————————
[INFO] BUILD FAILURE
Is it something wrong with the dependency? I tried the with
all different options and also googled it, but could not able to figured out
what was the problem. I’m really blocked here. any help/pointers are greatly
appreciated.
Thanks in advance.
Rams.
Hi,
am try to build my maven project…but i got an error
Failed to read artifact descriptor for org.fusesource.jansi:jansi:jar:1.1: Could not transfer artifact org.fusesource.jansi:jansi:pom:1.1 from/to jansi (http://jansi.fusesource.org/repo/release): Connection to http://jansi.fusesource.org refused: Connection timed out
bcse..jansi.pom file now available only in http://repo.fusesource.org/repo/release
am just install jansi.pm file in my local repository folder(following u r website) …
but again got same error,…how to fix it,…???
To generate the pom automatically just add -DgeneratePom=true to the command
hi..
I’m getting follwing error.please what can i do for that?
run code
mvn install:install-file -Dfile=~//Desktop//kaptcha-2.3.2.jar -DgroupId=com.google.code -DartifactId=kaptcha -Dversion=2.3.2 -Dpackaging=jar
error
[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 6.279s
[INFO] Finished at: Sun Jul 27 19:36:31 IST 2014
[INFO] Final Memory: 6M/90M
[INFO] ————————————————————————
[ERROR] No plugin found for prefix ‘install’ in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/home/samith/.m2/repository), central (http://search.maven.org/)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException
sorry the -Dfile as follows without double slash
-Dfile=~/Desktop/kaptcha-2.3.2.jar
I recently created a small UI util to install libraries in the local repository. It does the same as described in the article. The name is: maven-install-ui and can be found on github
Thank you so much! you save my life…
Thank you very much!
Regards
Hai it’s great..
Thank u so much..
Thanx Man !
Very Helpful 🙂
I did like that but im getting:
missing artifact
I need this library :https://code.google.com/p/redmine-jconnector/
Thanks!. Worked for me
hi mkyong
you are the best really
Hi,mkyong, I am installing ojdbc6.jar to my local repository, the install command is just like you write in article and ojdbc6.jar is copied to local repo, then I try to search this artifact in eclipse pom Dependencies panel, I can’t find this artifact, I try to add in pom.xml manually, it works. So what can I do to make sure I can search out this newly installed artifact? My command line maven and eclipse maven use the same local repository.
I get answer from stackoverflow:http://stackoverflow.com/questions/16355108/why-cant-i-find-my-own-installed-artifact-in-eclipse-search-dialog, hope can help others with same question.
What is that you haven’t still written about! I found an article for everything I look around for! Thanks!
Well, it worked for me too.. thanks man!
Worked for me! Thanks :).