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.
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 :
Warning
It’s always recommended to run “clean” and “install” together, so that you are always deploy the latest project to your local repository.
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>
Where do you run the mvn install command if you are using IntelliJ?
on command line, in your checkout directory.
What is the difference between pom.xml and dependency-reduced-pom.xml files?
I think mvn used the latter when I ran it?
Very nice and useful pointers for all things related with open source SW
Very intuitive…
I want to install spring frame work to my maven repository using eclipse. What is the URL I have to use for this?