Languages
[Edit]
EN

Maven difference between package and install

5 points
Created by:
Root-ssh
177560

Hi, today I would like to explain the difference between maven package and maven install.

1. mvn install - will build our jar + put it into target dir and copy it to maven .m2 repository on our PC, example of maven local repository path:

C:\Users\seth\.m2\repository\com\dirask\0.0.1-SNAPSHOT\dirarsk-examples-0.0.1-SNAPSHOT.jar

2. mvn package - will build our jar + put it into target dir, nothing more and nothing less


From maven documentation:

  1. install - install the package into the local repository, for use as a dependency in other projects locally
  2. package - take the compiled code and package it in its distributable format, such as a JAR.

Maven clean - why to run it in the first place?

mvn clean - will remove our target directory

It is good practice to run maven clean command before running mvn install or mvn package command. Maven clean will remove our target directory and in that way we will ensure our code and resources are freshly compiled to target directory.

Personally I like to use 2 maven commands to build my project.

First, just simple clean install:

$ mvn clean install

Second, clean install with skipping unit tests to save my time if something went wrong during development and I really need this jar fast for dev testing:

$ mvn clean install -Dmaven.test.skip=true

References

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Maven

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join