Maven的优点:
1、约定大于配置,标准化了项目布局,统一构建生命周期
2、用坐标进行统一的依赖管理,坐标是组织名、工件名、版本(groupId,artifactId,version)
maven生命周期的任务如下:
和生命周期中的8个阶段是一一对应的,没有集成测试阶段,但是多了一个site和clean
分别执行了一下,
validate,验证项目没啥输出
compile,在target目录下输出了编译后的class文件,
test,执行单元测试,
package,在target下生成了my-app-1.0.jar
verify,再次验证,没啥输出,没看明白这个的用途
install,把my-app-1.0.jar和pom.xml放入本地m2仓库,输出如下
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-app --- [INFO] Installing /Users/lakeslove/git/learn/gradle/gradleInAction/gradle-in-action-source/chapter01/listing_01_02-maven-build/target/my-app-1.0.jar to /Users/lakeslove/.m2/repository/com/mycompany/app/my-app/1.0/my-app-1.0.jar [INFO] Installing /Users/lakeslove/git/learn/gradle/gradleInAction/gradle-in-action-source/chapter01/listing_01_02-maven-build/pom.xml to /Users/lakeslove/.m2/repository/com/mycompany/app/my-app/1.0/my-app-1.0.pom
site,构建一个能被浏览器访问的站点,一直没成功。
deploy,把jar放入远程仓库,没成功
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ my-app --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.009 s [INFO] Finished at: 2020-05-21T23:19:26+08:00 [INFO] Final Memory: 12M/309M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project my-app: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
clean,把target删除了
至于怎么打成war包放入tomcat,目前不清楚。
不过我们以前的项目用的springboot,打包后直接就可以启动。