What is the difference between mvn package and mvn install?
Options
- There is no difference between them in Maven builds
packagemakes the JAR;installalso copies it to ~/.m2 (Correct option)installdeletes the JAR fromtarget/after buildingpackageuploads the JAR to the internet repository
Answer
package builds the JAR in target/; install also copies it into your local Maven repository (~/.m2) so other local projects can depend on it
Why
Both compile, test and package. mvn package stops after creating the JAR/WAR in the target/ folder.
mvn install goes further and copies the artifact into the local repository (~/.m2/repository), so other projects on your machine can use it as a dependency.
mvn deploy goes even further and uploads to a shared remote repository (Nexus, Artifactory) for your team.
A common daily command is mvn clean install.
mvn clean install # delete target/, build, test, install locally
mvn clean package -DskipTests # build without running testsRemember
package = JAR in target. install = + local repo. deploy = + remote repo.