转+总结!! maven的package与install命令区别

如果b项目依赖a项目,而a打了包(package),jar仅仅时打到了a项目的target下。这时编译b项目,还是会报错,找不到所依赖的a项目,说明b项目在本地仓库是没有找到它所依赖的a项目。

然后,我install a项目这时,有以下日志,[INFO] Installing G:projectsa argeta-0.0.1-SNAPSHOT.jar to F: epositorycomchenjuna .0.1-SNAPSHOTa-0.0.1-SNAPSHOT.jar
[INFO] Installing G:projectsapom.xml to F: epositorycomchenjuna .0.1-SNAPSHOTa-0.0.1-SNAPSHOT.pom,

说明a项目已安装到本地仓库了,并且是jar和pom同时安装的.

这时候去compile b项目,编译通过.

总之,package是把jar打到本项目的target下,而install时把target下的jar安装到本地仓库,供其他项目使用.

(-----以上转自:http://blog.csdn.net/bawcwchen/article/details/46957627)

maven常用命令

package:负责打包项目到本项目target路径下(take the compiled code and package it in its distributable format, such as a Jar/War/Ear.)

clean:清除target目录的文件

install:生成jar包并安装到本地maven仓库(xx/.m2/xx),可供其他项目调用(install the package into the local repository, for use as a dependency in other projects locally)

compile:编译项目(compile the source code of the project)

test:执行测试代码(test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed)

平时打包要发布的项目(指定环境dev/test/prod):mvn clean package -Dmaven.test.skip=true -Pprod 

-P xxx 会激活项目下的pom.xml配置的<profiles>标签下id为xxx 的相关配置

Maven Phases

Although hardly a comprehensive list, these are the most common default lifecycle phases executed.

  • validate: validate the project is correct and all necessary information is available
  • compile: compile the source code of the project
  • test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package: take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test: process and deploy the package if necessary into an environment where integration tests can be run
  • verify: run any checks to verify the package is valid and meets quality criteria
  • install: install the package into the local repository, for use as a dependency in other projects locally
  • deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

There are two other Maven lifecycles of note beyond the default list above. They are

  • clean: cleans up artifacts created by prior builds
  • site: generates site documentation for this project