How do I install a project artifact in my local maven repository?
Author: Deron Eriksson
Description: This tutorial describes how to install a project artifact in your local maven repository.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)


A primary idea behind mavenSW is the idea of repositories. A repository is essentially a collection of artifacts and metadata. An "artifact" in maven is a deployable file such as a jarW, warW, or earW file. The maven "central repository" is a remote library that has lots and lots of common artifacts (primarily different versions of common jar libraries) that serves as the standard place where you can get jar files for your projects. In addition, you can contact mirrors of the central repository. You can also utilize tools such as ArchivaS to selectively mirror a central repository (it'll mirror only the jar files that you require).

If you're using maven, you have a local maven repository on your machine. This serves as a location for all of the common jar files (and other similar resources) that your projects need to utilize. While developing a project, you typically reference these local repository jar files in your classpathW. When you package a project, you can selectively get these resources from your local repository and include them in your packaged project, if desired.

If we package a project and install it into our local maven repository (as a jar file or similar resource), it can be utilized in other local projects as a jar file. As an example of how this might be useful, you might have a common jar library that is utilized in multiple web applications (war files). Typically, you can build the jar file and then build the war files with those jar files packaged into them (in their lib directories).

To install a project's artifact (such as a jar or war file) into the local maven repository, we can execute the following command:

mvn install

The above maven command will execute all the goals tied to all the phases of the maven default build lifecycle up to and including the install phase. The "install" phase is the phase that takes a built artifact (which is built during the "package" phase) and copies it to the local maven repository.

I created an EclipseSW External Tool Configuration to perform a "mvn install" so that I can select a project in Eclipse and execute a "mvn install" on the project.

External Tool Configuration for 'mvn install'

I executed the "mvn install" External Tool Configuration on "mytest", which generated the following console output.

Console output from executing install goal

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building mytest
[INFO]    task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] Surefire report directory: C:\dev\workspace\mytest\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.maventest.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.036 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] [jar:jar]
[INFO] [install:install]
[INFO] Installing C:\dev\workspace\mytest\target\mytest-1.0-SNAPSHOT.jar to \dev\m2repo\com\maventest\mytest\1.0-SNAPSHOT\mytest-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Fri Feb 01 17:12:32 PST 2008
[INFO] Final Memory: 6M/12M
[INFO] ------------------------------------------------------------------------

As you can see from the console output, the project artifact was installed into my local maven repository at \dev\m2repo\com\maventest\mytest\1.0-SNAPSHOT\mytest-1.0-SNAPSHOT.jar. We can verify this by examining the local maven repository in the file system via the Windows Explorer.

'mytest' installed to local maven repository