Main Tutorials

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 Author

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

Comments

Subscribe
Notify of
6 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Radhika Parik
8 years ago

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

sarneet
8 years ago
Reply to  Radhika Parik

on command line, in your checkout directory.

Bram
11 months ago

What is the difference between pom.xml and dependency-reduced-pom.xml files?
I think mvn used the latter when I ran it?

Ron
10 years ago

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

Benson
10 years ago

Very intuitive…

Susanta
8 years ago

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