(1)创建web项目
mvn archetype:create  -DgroupId=com.mycompany.webapp  -DartifactId=myweb  -DarchetypeArtifactId=maven-archetype-webapp

(2)转化成java项目
cmd 进入项目目录下,执行:
mvn eclipse:eclipse

(3)打包而不测试
mvn package -DskipTests=true

mvn clean install -DskipTests=true

(4)打jar包时,复制依赖包:
mvn dependency:copy-dependencies

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin
    </artifactId>
    <configuration>
     <outputDirectory>${basedir}/app/lib
     </outputDirectory>
    </configuration>
 </plugin>

(5)运行测试:
   <plugin>
       <groupId>org.mortbay.jetty</groupId>
       <artifactId>maven-jetty-plugin</artifactId>
   </plugin> 
           
mvn jetty:run

(6)安装第三方包: 
mvn install:install-file -DgroupId=org.slf4j -DartifactId=slf4j-log4j12 -Dversion=1.5.6 -Dfile=slf4j-log4j12-1.5.6.jar -Dpackaging=jar -DgeneratePom=true

备注:
mvn install:install-file    
  -DgroupId=<your_group_name>     
  -DartifactId=<your_artifact_name>     
  -Dversion=<snapshot>     
  -Dfile=<path_to_your_jar_file>     
  -Dpackaging=jar    
  -DgeneratePom=true

简单解释一下:
archetype 是一个内建插件,他的create任务将建立项目骨架
archetypeArtifactId   项目骨架的类型

可用项目骨架有:
* maven-archetype-archetype
* maven-archetype-j2ee-simple
* maven-archetype-mojo
* maven-archetype-portlet
* maven-archetype-profiles (currently under development)
* maven-archetype-quickstart
* maven-archetype-simple (currently under development)
* maven-archetype-site
* maven-archetype-site-simple, and
* maven-archetype-webapp

(7)解决maven传递依赖中的版本冲突

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>
     maven-project-info-reports-plugin
    </artifactId>
   </plugin>
   
mvn project-info-reports:dependencies 。生成项目依赖的报表,这样你就能够在报表中找出你版本冲突的相关性依赖了。

最后在相应的dependency中加上exclusions来排除相关的传递依赖。

例:

<dependency>
                        <groupId>jaxen</groupId>
                        <artifactId>jaxen</artifactId>
                        <version>1.1.1</version>
                        <exclusions>
                                <exclusion>
                                        <groupId>com.ibm.icu</groupId>
                                        <artifactId>icu4j</artifactId>
                                </exclusion>
                        </exclusions>
                        <scope>runtime</scope>
                </dependency>

备注pom的简要例子:

<?xml version="1.0" encoding="UTF-8"?>
<project>
 <modelVersion>4.0.0</modelVersion>
 <groupId>mypro</groupId>
 <artifactId>mypro</artifactId>
 <version>0.0.1</version>
 <description></description>

<build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
     <outputDirectory>${basedir}/app</outputDirectory>
     <archive>
      <manifestFile>${basedir}/MANIFEST.MF</manifestFile>
          <manifest>
             <addClasspath>true</addClasspath>

<classpathPrefix>lib/</classpathPrefix>

<mainClass>com.mypro.Main </mainClass>

</manifest>

</archive>
     <excludes>
      <exclude>system.properties</exclude>
     </excludes>
    </configuration>
   </plugin>
            <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
     <source>1.6</source>
     <target>1.6</target>       
        <encoding>UTF-8</encoding>            
    </configuration>
    </plugin>  
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin
    </artifactId>
    <configuration>
     <outputDirectory>${basedir}/app/lib
     </outputDirectory>
    </configuration>
   </plugin>
  </plugins>
 </build>

<dependencies>
     <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring</artifactId>
   <version>2.5.5</version>
  </dependency>
  <!--  javax/activation/activation/1.1  org.apache.geronimo.modules/geronimo-activation/1.2-beta-->
  <dependency>
      <groupId>javax.activation</groupId>
   <artifactId>activation</artifactId>
   <version>1.1</version>
  </dependency>
  <!-- com/cedarsoft/commons/mail/1.4.3:--> 
  <dependency>
      <groupId>javax.mail</groupId>
   <artifactId>mail</artifactId>
   <version>1.4.3</version>
  </dependency>   
  <dependency>
   <groupId>commons-lang</groupId>
   <artifactId>commons-lang</artifactId>
   <version>2.3</version>
  </dependency>
  <dependency>
   <groupId>commons-io</groupId>
   <artifactId>commons-io</artifactId>
   <version>1.4</version>
  </dependency>
  <dependency>
   <groupId>commons-logging</groupId>
   <artifactId>commons-logging</artifactId>
   <version>1.0.4</version>
  </dependency>
  <dependency>
   <groupId>log4j</groupId>
   <artifactId>log4j</artifactId>
   <version>1.2.14</version>
  </dependency>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.8.1</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>ojdbc</groupId>
   <artifactId>ojdbc</artifactId>
   <version>14</version>
  </dependency>
 </dependencies>
</project>

最新文章

  1. 导出Redis某个列表所有数据的语句
  2. wordpress表结构
  3. 【poj1236】 Network of Schools
  4. C/C++函数参数读取顺序
  5. php学习笔记1--开发环境搭建:apache+php+mysql
  6. AMQ学习笔记 - 20. 使用Apache ActiveMQBrowser监控ActiveMQ
  7. RTNETLINK answers: File exists错误
  8. [转] Linux下查看文件和文件夹大小
  9. Android中如何查看内存(下)
  10. js原型链部分详细使用说明案例
  11. GIT_服务器与本地环境构建
  12. 通过jQuery和C#分别实现对.NET Core Web Api的访问以及文件上传
  13. Node.js - 阿里Egg的多进程模型和进程间通讯
  14. [android] 分析setting源代码获取SD卡大小
  15. codeforces285C
  16. sql-leetcode Consecutive Numbers
  17. 每篇半小时1天入门MongoDB——1. MongoDB介绍和安装
  18. Django多域名配置之Django-hosts插件的使用
  19. Charlie&#39;s Change(完全背包+路径记忆)
  20. tensorboard-sklearn数据-loss

热门文章

  1. SAX方式解析XML
  2. 【转】文件恢复神器extundelete
  3. [转]Permission denied: /.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
  4. vim打开文件时显示行号
  5. Jquery 中each循环嵌套的使用示例教程
  6. 获取浏览器版本Asp.Net
  7. STL--G - For Fans of Statistics(两个推断条件-二分)
  8. android获取View上某点的颜色
  9. paip.按键替换映射总结
  10. Genymotion 插件在 Eclipse 和 Android Studio 中点击后无法初始化 Initialize Engine: failed 解决方法