mvn install
and mvn package
are both Maven commands, but they serve different purposes:
-
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.
-
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.
- 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
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)