mvn install

The mvn install command is used in Apache Maven to compile, test, and package your project, and then install the resulting JAR or WAR file into the local Maven repository on your machine. This allows other Maven projects on the same machine to reference this artifact as a dependency.

Steps Maven Executes During mvn install

  1. Validate: Checks if the project is correctly configured and all necessary information is available.
  2. Compile: Compiles the source code of the project.
  3. Test: Runs the unit tests to ensure the code is functioning as expected.
  4. Package: Packages the compiled code into a JAR, WAR, or other distributable format as defined in the pom.xml.
  5. Install: Copies the package to the local Maven repository (usually located at ~/.m2/repository).

Typical Usage

Run the following command in the root directory of your Maven project:

mvn install

Common Use Cases

  1. Local Dependency Sharing: When you're working on multiple Maven projects, you can use mvn install on one project so others can reference it as a dependency.

    <dependency> <groupId>com.example</groupId> <artifactId>my-library</artifactId> <version>1.0.0</version> </dependency>

  2. Build Artifacts: Use this command to generate final build artifacts (e.g., JAR, WAR) that can be deployed.

Notes

  • If the build fails during any of the phases, Maven will stop the process and report the errors.
  • Ensure all tests pass before using mvn install, or use -DskipTests to skip tests:

    mvn install -DskipTests

  • To clean the previous build artifacts before installing, you can use:

    mvn clean install

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值