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.

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.

In this tutorial, we will show you how to install the “kaptcha” jar into our Maven local repository.

Update
The kaptcha is available in 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

After installed, just declares the kaptcha dependency normally.


  <dependency>
      <groupId>com.google.code</groupId>
      <artifactId>kaptcha</artifactId>
      <version>2.3</version>
 </dependency>

Done.

References

  1. Maven install file documentation
  2. Kaptcha website

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
49 Comment threads
15 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
47 Comment authors
DiegokikiDave CzerniawskivinayHima Bindu Recent comment authors
newest oldest most voted
vinay
Guest
vinay

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.

jntme
Guest
jntme

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?

Dave Czerniawski
Guest
Dave Czerniawski

thank you. what i needed and simple.

Hima Bindu
Guest
Hima Bindu

Thank you, It worked for me. It saved my time

Sawa Sud
Guest
Sawa Sud

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?

adi
Guest
adi

worked perfectly for me

Rams
Guest
Rams

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… Read more »

manaf
Guest
manaf

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,…???

emylyano3
Guest
emylyano3

To generate the pom automatically just add -DgeneratePom=true to the command

tech_user
Guest
tech_user

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… Read more »

tech_user
Guest
tech_user

sorry the -Dfile as follows without double slash
-Dfile=~/Desktop/kaptcha-2.3.2.jar

Andre Albert
Guest
Andre Albert

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

Jueser
Guest
Jueser

Thank you so much! you save my life…

msesiom
Guest
msesiom

Thank you very much!

Regards

trackback
Your first JavaFX app | Programming Percolatory

[…] Go to the command prompt and type this (example taken from here): […]

trackback
ADD JAR OR LIBRARY TO NETBEANS MAVEN PROJECT. | snippetjournal
Suresh
Guest
Suresh

Hai it’s great..

Thank u so much..

Amol Sharma
Guest
Amol Sharma

Thanx Man !
Very Helpful :)

gurpinars
Guest
gurpinars

I did like that but im getting:
missing artifact

gurpinars
Guest
gurpinars
Meenakshi
Guest
Meenakshi

Thanks!. Worked for me

nizar
Guest
nizar

hi mkyong
you are the best really

trackback
Menambahkan Library Pada Repository Local Maven di Netbeans | HaPe

[…] ini terinspirasi dari website http://www.mkyong.com dimana disitu dijelaskan bahwa kita bisa menambahkan library ke repository local secara manual. […]

Hiway
Guest
Hiway

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.

Hiway
Guest
Hiway

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.

Sunil
Guest
Sunil

What is that you haven’t still written about! I found an article for everything I look around for! Thanks!

anand babu
Guest
anand babu

Well, it worked for me too.. thanks man!

Parris
Guest
Parris

Worked for me! Thanks :).

Osmel de jesus Quintero Muñoz
Guest
Osmel de jesus Quintero Muñoz

Hi mkyong,

I can not install any one plugin into my local repository, and I don´t know why.

Into cmd:

C:\>mvn install:install-file -Dfile=c:\maven-clean-plugin-2.4.1.jar -Dgroupid=or
g.apache.maven.plugins -DartefactId=maven-clean-plugin -Dversion=2.4.1 -Dpackagi
ng=jar
[INFO] Scanning for projects…
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom
14-dic-2012 16:39:54 org.apache.maven.wagon.providers.http.httpclient.impl.clien
t.DefaultRequestDirector tryExecute
INFO: I/O exception (java.net.SocketException) caught when processing request: C
onnection reset

tumit
Guest
tumit

How to add dependencies of jar in command line?

Jayaram
Guest
Jayaram

Hi, I followed the steps you mentioned. Step 1: using wsimport I generate the class file Step 2: using jar -cvf command I create a jar named TestClient.jar Step 3: From the same directory I issued the command like: mvn install:install-file -Dfile= /Users/Jayaram/TestClient/FriendsMirrorRegisterClient.jar -DgroupId=com.friendsmirror.register.ws.client -DartifactId=friendsMirrorRegisterClient -Dversion=0.1 -Dpackaging=jar OutPut: [INFO] Scanning for projects… [INFO] ———————————————————————— [INFO] BUILD FAILURE [INFO] ———————————————————————— [INFO] Total time: 0.108s [INFO] Finished at: Sun Jun 24 16:13:36 GMT+05:30 2012 [INFO] Final Memory: 2M/81M [INFO] ———————————————————————— [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/Users/Jayaram/TestClient). Please verify you… Read more »

Jakub
Guest
Jakub

this command works fine when run in plain cmd instead of win powershell

Kaustubh Subhash Joshi
Guest
Kaustubh Subhash Joshi

Hi, I’ve following scenario with jenkins, i’m able to run custom jars via command prompt using maven but when I configure any maven or free style job then job is failing due to following error-
ERROR] Failed to execute goal on project ConnectorAutomation: Could not resolve dependencies for project com.cisco.connector.tests:ConnectorAutomation:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: ere:ere-core-api:jar:9.0.10, Could not find artifact aie:aie-core-api:jar:4.0.10 in central (http://repo.maven.apache.org/maven2) -> [Help 1]
[ERROR]

How to resolve such error to use in full cycle phase?

Siddhanta Kumar Pattnaik
Guest
Siddhanta Kumar Pattnaik

Hi All,
Can any one tell me what is the purpose of groupId,arifactId tag in dependency tag and -Dpackaging property in the mvn command ………

Siddhanta Kumar Pattnaik
Guest
Siddhanta Kumar Pattnaik

Hi All,
Can any one tell me what is the purpose of , in tag and -Dpackaging property in the mvn command ………