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>
Tags :
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 making a donation to the charity, thanks.

Related Posts

Popular Posts