DEV Community

Code Green
Code Green

Posted on • Edited on

2

Difference between mvn install and mvn package

mvn install and mvn package are both Maven commands, but they serve different purposes:

  1. mvn install:

    • This command compiles the source code of your project, runs any tests, and packages the compiled code into a JAR or WAR file.
    • It then copies the packaged artifact (JAR or WAR) into the local Maven repository, making it available to other projects locally on your machine.
    • It is typically used to install your project's artifacts into the local repository for use in other projects that depend on it.
  2. mvn package:

    • This command also compiles the source code of your project, runs tests, and packages the compiled code into a JAR or WAR file, similar to mvn install.
    • However, unlike mvn install, it does not install the generated artifact into the local Maven repository.
    • Instead, it only creates the packaged artifact in the target directory of your project's build directory.
    • It is commonly used to generate the packaged artifact for distribution or deployment, without installing it into the local repository.

In summary, while both commands compile source code, run tests, and package the compiled code into an artifact, mvn install additionally installs the artifact into the local Maven repository, whereas mvn package simply creates the artifact in the project's target directory without installing it locally.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay