How to install your project into Maven local repository

In Maven, you can use “mvn install” to package your project and deploy to local repository automatically, so that other developers can use it.


mvn install
Note
When “install” phase is executed, all above phases “validate“, “compile“, “test“, “package“, “integration-test“, “verify” phase , including the current “install” phase will be executed orderly. Refer to this Maven lifecycle for detail.

mvn install example

A Java project, with following pom.xml file

File : pom.xml


<project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
  http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mkyong.core</groupId>
  <artifactId>mkyong-core</artifactId>
  <packaging>jar</packaging>
  <version>99</version>
  <name>mkyong-core</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.4</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Based on above pom.xml file, when “mvn install” is executed, it will package the project into “mkyong-core-99.jar” file and copy to your local repository. See following diagram :

Install project to Maven local repository
Warning
It’s always recommended to run “clean” and “install” together, so that you are always deploy the latest project to your local repository.


mvn clean install

Access Deployed Project

Now, other developers are able to access your deployed “jar” file by declaring below dependency tag in their pom.xml file.


<dependency>
      <groupId>com.mkyong.core</groupId>
      <artifactId>mkyong-core</artifactId>
      <version>99</version>
 </dependency>

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Susanta
Guest
Susanta

I want to install spring frame work to my maven repository using eclipse. What is the URL I have to use for this?

Radhika Parik
Guest
Radhika Parik

Where do you run the mvn install command if you are using IntelliJ?

sarneet
Guest
sarneet

on command line, in your checkout directory.

Ron
Guest
Ron

Very nice and useful pointers for all things related with open source SW

Benson
Guest
Benson

Very intuitive…