There are 2 cases where you need to issue the MAVEN command manually including a jar to Maven's local repository.
- The jar to be used does not exist in the central repository of Maven.
- You have created a custom jar, and another Maven project needs to be used.
PS, or there are many jars that do not support Maven.
Case study
For example, Kaptcha, which is a popular third-party Java library, is used to generate "captcha" images to block spam, but it is not in Maven's central repository.
In this tutorial, we'll show you how to install the "Kaptcha" jar into Maven's local repository.
1. MVN Installation
Download "Kaptcha", unzip it and copy the Kaptcha-version.jar to another place, such as: C drive. Issue the following command:
MVN install:install-file-dfile=c:\kaptcha-{version}.jar-dgroupid=com.google.code-dartifactid=kaptcha-dversion={ Version}-dpackaging=jar
Example:
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 13:41:42 SGT 2014[info] Final Memory:3m/6m[info]---- --------------------------------------------------------------------
Now, the "Kaptcha" jar is copied to the Maven local repository.
2. Pom.xml
After the installation is complete, declare the coordinates of Kaptcha in Pom.xml.
<dependency> <groupId>com.google.code</groupId> <artifactid>kaptcha</ artifactid> <version>2.3</version> </dependency>
3. Complete
Build it, and now the "Kaptcha" jar can be retrieved from your Maven local repository.
Package non-Maven managed jars into the MAVEN local repository