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.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay