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.

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.

Update
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.

pom.xml

	<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:

pom.xml

	<dependency>
		<groupId>com.google.code</groupId>
		<artifactId>kaptcha</artifactId>
		<version>2.3</version>
		<scope>system</scope>
		<systemPath>d:/projects/kaptcha.jar</systemPath>
	</dependency>
pom.xml

	<dependency>
		<groupId>com.google.code</groupId>
		<artifactId>kaptcha</artifactId>
		<version>2.3</version>
		<scope>system</scope>
		<systemPath>${project.basedir}/lib/kaptcha.jar</systemPath>
	</dependency>

References

author image

mkyong

Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities. Read all published posts by

Comments

avatar
52 Comment threads
15 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
50 Comment authors
RASbachirGourav SaklechamkyongDiego 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?

trackback
How to convert Eclipse Java web project to Maven project | Maven

[…] P.S For custom library, you need to install it into your Maven Local Repository manually. […]

Alex Turetsky
Guest
Alex Turetsky

Make sure to add -Dpackaging=jar to that mvn:install command. This parameter is not optional. (In your instructions, it appears in the result section, but not in the command)

prabhu
Guest
prabhu

Thanks a lot for your effort. It helped a lot. Thanks!

Enkay
Guest
Enkay

Thanks for the detailed simple steps!!!

Issam
Guest
Issam

Thanks a lot… Your steps were simple and very helpful…

serortlop
Guest
serortlop

Thanks a lot!!!!!
it was really a great. Simple and easy as everything must be.

trackback
Struts 2 + Hibernate integration with “Full Hibernate Plugin”

[…] Install library into Maven local repository Oracle Magazine (Free) Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. […]

trackback
How to include library manually into maven local repository? « Thinking Mind

[…] that it could compile the project source files. Quick google search landed me on this page – http://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/, which had the exact solution to my […]

Sharaf
Guest
Sharaf

thanx alot it made simple to add my own jar and not to place into nexus.

Macluq
Guest
Macluq

Yeah, but sometimes you need to add it into Nexus (so other people can use it in your organization, for example).

trackback
How to add Oracle JDBC driver in your Maven local repository

[…] How to include library manually into Maven local repository [ Read More ] You can find more similar articles at Maven Tutorials […]

trackback
Maven Tutorial

[…] library in tradition way and Maven way, and explains where Maven will search those library.Install custom library into Maven local repository Many libraries are still not support Maven pom.xml concept, here’s a guide to show how to […]

red
Guest
red

Hi! Thank you for tutorial but how can I add a jar library that uses native external libraries (.dll, .so)?

praneeth
Guest
praneeth

How to create custom project structure with Maven (step by step mkyong style).

Thank you,
Praneeth.

AKS
Guest
AKS

Great, you are so good to explain things in a simple manner. How do we do the same if I have to install a library or project to nexsus repository?

Abhishek
Guest
Abhishek

Hi,
I have a requirement in which I have to uplaod the internally created jar(project related) to repo without version.
Please sujjest how to do that.
Thanks!! 🙂

gagaeloel
Guest
gagaeloel

For me works this:

mvn install:install-file -DgroupId=com.google.code.kaptcha -DartifactId=kaptcha -Dversion=2.3 -Dpackaging=jar -Dfile=kaptcha-2.3.jar

instead of “…-DgroupId=com.google.code … “

gagaeloel
Guest
gagaeloel

forget my answer, i was wrong

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

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

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?

tumit
Guest
tumit

How to add dependencies of jar in command line?

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

Parris
Guest
Parris

Worked for me! Thanks :).

anand babu
Guest
anand babu

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

Sunil
Guest
Sunil

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

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.

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. […]

nizar
Guest
nizar

hi mkyong
you are the best really

Meenakshi
Guest
Meenakshi

Thanks!. Worked for me