maven的常用命令分享

整理秀逗的脑袋 发布于 2011/09/22 10:45
阅读 806
收藏 6

【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”

1. 创建Maven的普通java项目:mvn archetype:create -DgroupId=“xx” -DartifactId=“xx”-DpackageName="xx" -Dversion="xx"

2. 创建Maven的Web项目:mvn archetype:create -DgroupId=“xx”-DartifactId=“xx”-DpackageName="xx" -Dversion="xx"-DarchetypeArtifactId=maven-archetype-webapp

3. 编译源代码: mvn compile
4. 编译测试代码:mvn test-compile
5. 运行测试:mvn test
6. 产生site:mvn site
7. 打包:mvn package (一般直接使用: mvn clean package )
8. 清除产生的项目:mvn clean
9. 生成eclipse项目:mvn eclipse:eclipse
10.只打jar包: mvn jar:jar
11.当开发一个带有很多失败单元测试的系统 mvn test -Dmaven.test.failure.ignore=true

(可以在pom.xml中配置build标签

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>

)
12.想要整个的跳过测试 mvn install -Dmaven.test.skip=true

(可以在pom.xml中配置build标签

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

)

13.构建打包好的命令行应用程序

(1)配置pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
(2)运行:mvn install assembly:assembly

14.运行java主程序:mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main 运行Main.class

15.查看插件的帮助信息:mvn help:describe -Dplugin=exec -Dfull 查看exec插件的详细信息(关键时刻非常有用的一个插件)

16. 查看项目所有的依赖插件:mvn dependency:resolve

17.查看项目依赖插件的目录树:mvn dependency:tree

18.调试标记运行:mvn install -X

19.在本地 Repository 中安装 jar:mvn install(一般直接用mvn clean install)

20.

src/main/java :是项目编译时默认的编译文件位置。
src/main/resources :是项目资源文件默认存放的位置。

加载中
0
BigMaN
BigMaN
最近在用Maven 构建程序,越来越喜欢Maven了,
整理秀逗的脑袋
整理秀逗的脑袋
感觉用maven构建工程挺方便的
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部