maven学习(二)maven常用的命令

参考博客:(http://blog.csdn.net/keda8997110/article/details/20925449)

以下命令都是基于命令行的操作,也可以直接在eclipse等IDE上maven build中填写(不用写mvn前缀)

版本信息:

mvn -v 显示版本信息

mvn -h 帮助信息

生成项目:

mvn archetype:generate 根据提示信息选择需要生成哪种archetype类型的maven项目,也可以指定参数

mvn archetype:generate -DgroupId=组id -DartifactId=项目id -Dversion=版本号 -DarchetypeArtifactId=maven-archetype-webapp 生成一个webapp的maven项目

清理:
mvn clean 清理项目,通常和其他命令一块用,比如mvn clean install,先清理再安装到本地仓库

打包:
mvn package 打包项目到target目录下
mvn install 将模块安装到本地
mvn deploy 将模块发布到远程仓库

编译:
mvn compile 编译源码
mvn test-compile 编译测试代码

依赖结构:

mvn dependency:tree 打印项目依赖的树状结构
mvn dependency:list 打印项目依赖列表

源码下载:

mvn dependency:sources 依赖jar的源码就有了

测试:
mvn test 运行测试

打包:
mvn jar:jar 打jar包

站点:
mvn site 发布站点

所有这些命令都可以指定参数,如测试时跳过编译阶段:
mvn test -skiping compile -skiping test-compile 跳过编译、测试编译进行测试

比较实用,可以了解某个插件、组件的信息,手敲一下就能明白了:

mvn help:describe 参数有三种形式,任选其一:1.-Dcmd=install 2.-Dplugin=org.apache.maven.plugins:maven-help-plugin 3.-DgroupId=org.apache.maven.plugins -DartifactId=maven-help-plugin ,如果需要详细参数可以指定-Ddetail=true

运行:
mvn tomcat:run -Dmaven.test.skip=true -Dmaven.tomcat.port=9090 使用tomcat指定端口号启动,跳过测试

mvnDebug tomcat:run 可以调试的启动方式

发布到本地本地仓库:(摘自官网,http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html)

将jar包安装到本地仓库:mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>(有效,常用)

将pom安装到本地仓库:mvn install:install-file -Dfile=<path-to-file> -DpomFile=<path-to-pomfile>(未测试)

maven-install-plugin2.5以上的版本,如果jar是Apache Maven构建的,会在META-INF目录生成一个pom.xml,只需要执行此命令:
mvn install:install-file -Dfile=<path-to-file>(未测试)

发布到远程仓库:(摘自官网)

mvn deploy:deploy-file -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<type-of-packaging> -Dfile=<path-to-file> -DrepositoryId=<id-to-map-on-server-section-of-settings.xml> -Durl=<url-of-the-repository-to-deploy>(有效,常用)

如果需要生成pom文件:-DgeneratePom=false(未测试)

mvn deploy:deploy-file -DpomFile=<path-to-pom> -Dfile=<path-to-file> -DrepositoryId=<id-to-map-on-server-section-of-settings.xml> -Durl=<url-of-the-repository-to-deploy>(未测试)

原文地址:https://www.cnblogs.com/douJiangYouTiao888/p/6506326.html