How to include library manually into maven local repository?
There are still many Java libraries that are not support for Maven, or may be you want to create a custom library which is required to include it into your Maven local repository.
Fortunately, Maven comes with command to let you include your “non-maven-support” library into your Maven local repository easily.
Case study
For example, “kaptcha” is a third party library which is used to generate “captcha” image to stop spamming, but it did not support Maven.
Here’s a guide to show you how to install the “kaptcha” jar into your Maven’s local repository.
1. Install library – mvn install
Download the “kaptcha” jar file and put it into your “C:” drive, and issue following Maven’s command :
mvn install:install-file -Dfile=c:\kaptcha-2.3.jar -DgroupId=com.google.code -DartifactId=kaptcha -Dversion=2.3 -Dpackaging=jar
Result :
D:\>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] ------------------------------------------------------------------------
Now, the “kaptcha” jar library is included into your Maven local repository.
2. Modify pom.xml file
After installed, you can add the custom library details into your “pom.xml” file like this
<dependency> <groupId>com.google.code</groupId> <artifactId>kaptcha</artifactId> <version>2.3</version> </dependency>
3. Done
Build it, now the “kaptcha” jar is able to retrieve from your Maven local repository.
Hi! Thank you for tutorial but how can I add a jar library that uses native external libraries (.dll, .so)?
I don’t think Maven cant handle it automatically. You can still use Maven to add Java library but put your .dll or .so manually into project classpath.
[...] 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 [...]
[...] How to include library manually into Maven local repository [ Read More ] You can find more similar articles at Maven Tutorials [...]
thanx alot it made simple to add my own jar and not to place into nexus.
Yeah, but sometimes you need to add it into Nexus (so other people can use it in your organization, for example).
Yes, if your company is using Nexus or others to host a Maven repository server.
[...] 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 [...]
[...] 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. [...]
Thanks a lot!!!!!
it was really a great. Simple and easy as everything must be.
Thanks a lot… Your steps were simple and very helpful…
Thanks for the detailed simple steps!!!
[...] P.S For custom library, you need to install it into your Maven Local Repository manually. [...]
Thanks a lot for your effort. It helped a lot. Thanks!
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)
hi -Dpackaging=jar is a must in order for the install the mavan library manually into our local repository. Post is updated , thanks for it.
I Have one problem. This command is ok for a single Custom jar file. But we have 17 custom jars files in the file system. I do not want to write dependency in pom.xml file for each and every jars instead inside one dependecy through which all the jars will be available to build patha. Is there any way to to this. Please suggest me.