Maven 常用命令 - 简洁版

Maven库:

http://repo2.maven.org/maven2/

Maven依赖查询:

http://mvnrepository.com/

【Maven常用命令】 
1. 创建Maven的普通java项目: 
   mvn archetype:create 
   -DgroupId=packageName 
   -DartifactId=projectName  
2. 创建Maven的Web项目:   
    mvn archetype:create 
    -DgroupId=packageName    
    -DartifactId=webappName 
    -DarchetypeArtifactId=maven-archetype-webapp    
3. 清理编译:mvn clean compile
4. 清理测试:mvn clean test
5. 清理打包:mvn clean package  
6. 清理安装:mvn clean install
7. 生成eclipse项目:mvn eclipse:eclipse  
8. 生成idea项目:mvn idea:idea  
9. 编译测试的内容:mvn test-compile  
10. 只打jar包: mvn jar:jar  
11. 跳过测试:  mvn install -Dmaven.test.skip=true  
11. 指定端口:  mvn -Dmaven.tomcat.port=9090
12. 只测试而不编译,也不测试编译:mvn test -skipping compile -skipping test-compile ( -skipping 的灵活运用,当然也可以用于其他组合命令) 
13. 清除eclipse的一些系统设置: mvn eclipse:clean

通过cvs或svn下载代码到本机,然后执行mvn eclipse:eclipse生成ecllipse项目文件,然后导入到eclipse就行了;修改代码后执行mvn compile或mvn test检验,也可以下载eclipse的maven插件。

发布第三方Jar到本地库中: mvn install:install-file -DgroupId=com -DartifactId=client -Dversion=0.1.0 -Dpackaging=jar -Dfile=d:\client-0.1.0.jar。

【添加 jar 包到本地仓库】

mvn install:install-file 
  -DgroupId=xxx
  -DartifactId=xxx     
  -Dversion=1.0         //版本号
  -Dpackaging=jar               //类型
  -Dfile=d:\xxx-1.0.jar     //jar实际路径

添加打包插件:

复制代码

<plugin>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
       <source>1.6</source>
       <target>1.6</target>
       <encoding>UTF-8</encoding>
       <compilerArguments>
             <extdirs>src\main\webapp\WEB-INF\lib</extdirs>
       </compilerArguments>
    </configuration>
</plugin>

复制代码

【库版本选择】
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>[1.1,)</version>
</dependency>
表达式 含义
(,1.0] version<=1.0
[1.2,1.3] 1.2<=version<=1.3
[1.0,2.0) 1.0<=version<2.0
[1.5,) 1.5<=version
(,1.1),(1.1,) version!=1.1

【pom.xml 基本节点】
<project> 根节点
<modelversion> pom.xml 使用的对象模型版本
<groupId> 创建项目的组织或团体的唯一 Id
<artifactId> 项目唯一Id, 项目名
<packaging> 打包扩展名(JAR、WAR、EAR)
<version> 项目版本号
<name> 显示名,用于生成文档
<url> 组织站点,用于生成文档
<description> 项目描述,用于生成文档
<dependency>之<scope> 管理依赖部署

<scope> 可使用 5 个值:
compile 缺省值,用于所有阶段,随项目一起发布
provided 期望JDK、容器或使用者提供此依赖。如servlet.jar
runtime 只在运行时使用
test 只在测试时使用,不随项目发布
system 需显式提供本地jar,不在代码仓库中查找

猜你喜欢

转载自blog.csdn.net/hemeinvyiqiluoben/article/details/81462419