jar

[mvn install] How To install Jar File Into Maven Local Repository?

Posted on Updated on

There are cases that you need to issue Maven’s command to include a jar into the Maven local repository manually:
  1. The jar you want to use doesn’t exist in the Maven center repository.
  2. You created a custom jar, and need to use for another Maven project.
Example
For example,  spring4gwt.jar , a popular third party Java library, which is used to bridge spring and gwt, but it’s not available in the Maven center repository.
In this tutorial, I will show you how to install the “spring4gwt.” jar into your Maven’s local repository.
mvn install:install-file -Dfile=C:\spring4gwt.jar -DgroupId=com.google.code -DartifactId=spring4gwt -Dversion=0.0.1 -Dpackaging=jar
Demo.
C:\Users\guetampan\bluerock\workspace\mweb-1.0>mvn install:install-file -Dfile=C
:\Users\guetampan\bluerock\workspace\mweb-1.0\spring4gwt.jar -DgroupId=com.googl
e.code -DartifactId=spring4gwt -Dversion=0.0.1 -Dpackaging=jar
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for
com.bluerock.mweb:mweb:war:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-inst
all-plugin is missing. @ line 223, column 12
[WARNING] 'build.plugins.plugin.version' for org.codehaus.mojo:build-helper-mave
n-plugin is missing. @ line 177, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten t
he stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support buildin
g such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mweb 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ mweb ---
[INFO] Installing C:\Users\guetampan\bluerock\workspace\mweb-1.0\spring4gwt.jar
to C:\Users\guetampan\.m2\repository\com\google\code\spring4gwt.0.1\spring4gwt
-0.0.1.jar
[INFO] Installing C:\Users\GUETAM~1\AppData\Local\Temp\mvninstall137699429999557
0548.pom to C:\Users\guetampan\.m2\repository\com\google\code\spring4gwt.0.1\s
pring4gwt-0.0.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.089s
[INFO] Finished at: Tue Jan 08 16:06:54 SGT 2013
[INFO] Final Memory: 5M/121M
[INFO] ------------------------------------------------------------------------
C:\Users\guetampan\bluerock\workspace\mweb-1.0>

To check whether the file is in your maven folder, open your maven repository directory, in windows it should be under your {user directory}\.m2\repository. Following is the screenshot:
Now the spring4gwt.jar is ready to use. add the following into your pom.xml

<dependency>
<groupId>com.google.code</groupId>
<artifactId>spring4gwt</artifactId>
<version>0.0.1</version>
</dependency>