Maven多项目依赖配置,多maven项目聚合的实例

本文介绍一个多maven项目的实例demo,展示了聚合、继承、工程依赖、单元测试、多war聚合、cargo发布等场景 

一、工程介绍 

该项目由5个maven项目组成 

 

task-aggregator是父工程,同时承担聚合模块和父模块的作用,没有实际代码和资源文件 
task-common是基础工程,里面是公共的代码 
task-sla是某一个业务子模块,不包含web内容 
task-sla-web是某一个web子模块 
task-web-dist是最外围的web工程,聚合多个web工程,形成最终的war包 

依赖关系是:task-common <-- task-sla <-- task-sla-web <-- task-web-dist 

二、task-aggregator 

 

这个工程是起到聚合作用,并充当parent pom,所以没有任何实际代码和资源文件。我这里选择了平行结构,另外一种方式是树形结构,我个人感觉平行结构看起来更舒服一点 

下面是pom,有所简化: 
Xml代码   收藏代码
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  3.   
  4.     <!-- 定义公共变量 -->  
  5.     <properties>  
  6.         <spring.version>3.1.0.RELEASE</spring.version>  
  7.         <struts2.version>2.3.1</struts2.version>  
  8.         <hibernate.version>3.2.7.ga</hibernate.version>  
  9.     </properties>  
  10.   
  11.     <modelVersion>4.0.0</modelVersion>  
  12.     <groupId>com.xxx.task</groupId>  
  13.     <artifactId>task-aggregator</artifactId>  
  14.     <version>0.0.1-SNAPSHOT</version>  
  15.     <packaging>pom</packaging>  
  16.   
  17.         <!-- 待聚合模块 -->  
  18.     <modules>  
  19.         <module>../task-common</module>  
  20.         <module>../task-sla</module>  
  21.         <module>../task-sla-web</module>  
  22.         <module>../task-web-dist</module>  
  23.     </modules>  
  24.   
  25.     <!-- 配置部署的远程仓库 -->  
  26.     <distributionManagement>  
  27.         <snapshotRepository>  
  28.             <id>nexus-snapshots</id>  
  29.             <name>nexus distribution snapshot repository</name>  
  30.             <url>http://10.78.68.122:9090/nexus-2.1.1/content/repositories/snapshots/</url>  
  31.         </snapshotRepository>  
  32.     </distributionManagement>  
  33.   
  34.     <build>  
  35.   
  36.         <pluginManagement>  
  37.             <plugins>  
  38.   
  39.                 <plugin>  
  40.                     <groupId>org.apache.maven.plugins</groupId>  
  41.                     <artifactId>maven-resources-plugin</artifactId>  
  42.                     <version>2.6</version>  
  43.                     <configuration>  
  44.                         <encoding>UTF-8</encoding>  
  45.                     </configuration>  
  46.                 </plugin>  
  47.   
  48.                 <plugin>  
  49.                     <groupId>org.apache.maven.plugins</groupId>  
  50.                     <artifactId>maven-compiler-plugin</artifactId>  
  51.                     <version>2.5.1</version>  
  52.                     <configuration>  
  53.                         <encoding>UTF-8</encoding>  
  54.                     </configuration>  
  55.                 </plugin>  
  56.   
  57.             </plugins>  
  58.         </pluginManagement>  
  59.   
  60.     </build>  
  61.   
  62.     <dependencyManagement>  
  63.   
  64.         <dependencies>  
  65.   
  66.             <dependency>  
  67.                 <groupId>com.sun</groupId>  
  68.                 <artifactId>tools</artifactId>  
  69.                 <version>1.6.0</version>  
  70.                 <scope>system</scope>  
  71.                 <systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>  
  72.             </dependency>  
  73.   
  74.         </dependencies>  
  75.   
  76.     </dependencyManagement>  
  77.   
  78. </project>  

基本上是一目了然,只是有几点注意下: 

    1、这里配置了<distributionManagement>,这样子项目就不需要重复配置了 

    2、通过<pluginManagement>,对一些插件进行了公共的配置,这里主要是为了消除构建时的告警 

    3、配置tools,是因为实际中发现,其他开发人员从svn上check out工程以后,有的人会报错,找不到tools.jar,这样配置以后就好了 

三、task-common 

该工程是公共工程,提供了项目中的公共代码,这里只包括了通用的DAO组件,作为示例。 

该工程不依赖任何其他工程 

 

该工程里有几点要点: 

    1、在代码内部用了Spring的注解 
Java代码   收藏代码
  1. public abstract class GenericDAO<T> implements IGenericDAO<T> {  
  2.   
  3.     private Class<T> entityClass;  
  4.   
  5.     public GenericDAO(Class<T> clazz) {  
  6.         this.entityClass = clazz;  
  7.     }  
  8.   
  9.     @Autowired  
  10.     private HibernateTemplate hibernateTemplate;  
  11.   
  12. }  

这里用到了@Autowired注解,所以最终形成的war包,必须在spring配置文件中声明HibernateTemplate类型的bean,否则会报错 

我这里用的maven环境是maven3.0.4,这个版本打出的jar包,带有Directory Entries信息,所以spring的注解即使在jar包中也可生效,如果是比较老的版本,spring的注解在jar包中不好用,关于这个问题的详细描述,见另外一篇博客:http://kyfxbl.iteye.com/blog/1675368 

    2、单元测试的写法 
Java代码   收藏代码
  1. @RunWith(SpringJUnit4ClassRunner.class)  
  2. @ContextConfiguration(locations = "classpath:spring-test.xml")  
  3. @Transactional  
  4. public class GenericDAOTest {  
  5.   
  6.     @Autowired  
  7.     private IBookDAO bookDAO;  
  8.   
  9.     @Test  
  10.     public void testInsert() {  
  11.         Book book = new Book();  
  12.         book.setName("thinking in java");  
  13.         book.setIsbn("111");  
  14.         bookDAO.insert(book);  
  15.     }  
  16.   
  17. }  

这里用到了几个注解,@RunWith是为了在spring容器环境下跑这个单元测试类,以支持依赖注入。@ContextConfiguration是声明spring配置文件的位置。@Transactional注解之后,在单元测试方法中的事务会自动回滚,这个比较方便,这样在前面执行的方法,不会对后面的方法造成影响 

这个单元测试类,可以直接在maven里跑起来,让我比较惊喜。之前这样写,在ant里跑没有成功,可能是我没有找到合适的插件的原因 

    3、除了测试的java代码之外,还有3个资源文件,都是放在src/test/resources下,这些资源文件只在test阶段生效,package阶段不会被打包,也就是专门供测试阶段使用 

这个各有利弊,优点是测试的配置文件与开发的配置文件隔离,互不干扰。缺点是配置文件似乎缺少了集中放置的地点,这样如果多个maven工程都需要跑单元测试,要共享测试用配置文件,比较麻烦一点 

不过从我个人来看,也算是利大于弊。只是在每个maven项目下,都需要独立的测试相关资源文件,其实也有利于分别修改 

另外,可以看到这里的hibernate映射文件,不是和model类放在一个package下,而是放在resources目录下的,这样做可以避免一些潜在的问题,也有利于后续的聚合 

    4、pom文件没有什么特别的,只是要引入<scope>为test的junit和spring-test 

四、task-sla 

该工程依赖task-common(因为用到了GenericDAO),是某一个业务模块的逻辑部分,包含了数据库访问层和业务逻辑层,但是不包括web相关的部分 

 

这里没有什么特别要注意的,目录结构和task-common基本一样。比较特别的是可以看到Maven Dependencies里,有一个task-common工程,所以task-common里的任何修改,都可以第一时间在这个工程里体现出来,是比较方便的 

关于这个问题,见另外一篇博客:http://kyfxbl.iteye.com/blog/1679806 

另外就是前面说过的,hibernate的映射文件,应该放在src/main/resources下,而不是与Model类放在一起 

五、task-sla-web 

这个工程是上述task-sla工程的web层,依赖于task-sla,由于task-sla又依赖task-common,所以这个工程最终会同时依赖task-common和task-sla 

 

然后这个工程里包含了web层的东西,包括Action类、jsp、图片、struts2的配置文件等,这些东西放在web工程里是最合适的 

 

这里需要注意2点: 

    1、这个工程的packaging类型是war,而不是jar。但是最终它不会独立打出war包来,其src/main/webapp里的所有文件,都会被最外围的task-web-dist工程聚合成一个总的war 

    2、这个工程的WEB-INF目录下,没有web.xml(有也没用,最终会被覆盖)。默认情况下,packaging类型为war的项目,如果没有web.xml,则构建会失败,因此需要在pom里做一个配置 

该项目的pom如下,省略了依赖部分: 
Xml代码   收藏代码
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.   
  4.     <parent>  
  5.         <groupId>com.xxx.task</groupId>  
  6.         <artifactId>task-aggregator</artifactId>  
  7.         <version>0.0.1-SNAPSHOT</version>  
  8.         <relativePath>../task-aggregator</relativePath>  
  9.     </parent>  
  10.   
  11.     <modelVersion>4.0.0</modelVersion>  
  12.     <artifactId>task-sla-web</artifactId>  
  13.     <packaging>war</packaging>  
  14.   
  15.     <build>  
  16.         <plugins>  
  17.             <plugin>  
  18.                 <groupId>org.apache.maven.plugins</groupId>  
  19.                 <artifactId>maven-war-plugin</artifactId>  
  20.                 <configuration>  
  21.                     <failOnMissingWebXml>false</failOnMissingWebXml>  
  22.                 </configuration>  
  23.             </plugin>  
  24.         </plugins>  
  25.     </build>  
  26.   
  27.     <!-- 配置依赖 -->  
  28.     <dependencies>  
  29.         <dependency>  
  30.             <groupId>org.springframework</groupId>  
  31.             <artifactId>spring-beans</artifactId>  
  32.         </dependency>  
  33.   
  34.     </dependencies>  
  35.   
  36. </project>  

上面的<failOnMissingWebXml>,就是配置缺少web.xml也不使构建失败 

六、task-web-dist 

这个工程是最外围的web工程,起到聚合的作用,即把所有的web项目,打成最终的war包。同时,在这个工程里,放置里公共的配置文件,比如struts.xml、ssoconfig.properties等 

 

这个工程的聚合意图十分明显,比如struts.xml 
Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">  
  3.   
  4. <struts>  
  5.   
  6.     <constant name="struts.objectFactory" value="spring" />  
  7.     <constant name="struts.ui.theme" value="simple" />  
  8.     <constant name="struts.i18n.encoding" value="UTF-8" />  
  9.     <constant name="struts.action.extension" value="action" />  
  10.     <constant name="struts.enable.DynamicMethodInvocation" value="false" />  
  11.     <constant name="struts.devMode" value="true" />  
  12.   
  13.     <include file="struts2/struts-sla.xml" />  
  14.   
  15. </struts>  

提供了项目通用的配置,并把各子项目的struts2配置文件聚合起来。war包中的web.xml也是在这里提供的 

下面是该工程的pom,也省略了依赖的配置: 
Xml代码   收藏代码
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.   
  4.     <parent>  
  5.         <groupId>com.xxx.task</groupId>  
  6.         <artifactId>task-aggregator</artifactId>  
  7.         <version>0.0.1-SNAPSHOT</version>  
  8.         <relativePath>../task-aggregator</relativePath>  
  9.     </parent>  
  10.   
  11.     <modelVersion>4.0.0</modelVersion>  
  12.     <artifactId>task-web-dist</artifactId>  
  13.     <packaging>war</packaging>  
  14.   
  15.     <build>  
  16.   
  17.         <finalName>task</finalName>  
  18.   
  19.         <plugins>  
  20.   
  21.             <!-- 合并多个war -->  
  22.             <plugin>  
  23.                 <groupId>org.apache.maven.plugins</groupId>  
  24.                 <artifactId>maven-war-plugin</artifactId>  
  25.                 <configuration>  
  26.                     <packagingExcludes>WEB-INF/web.xml</packagingExcludes>    
  27.                     <overlays>  
  28.                         <overlay>  
  29.                             <groupId>com.huawei.inoc.wfm.task</groupId>  
  30.                             <artifactId>task-sla-web</artifactId>  
  31.                         </overlay>  
  32.                     </overlays>  
  33.                 </configuration>  
  34.             </plugin>  
  35.   
  36.             <!-- 利用cargo启动容器 -->  
  37.             <plugin>  
  38.                 <groupId>org.codehaus.cargo</groupId>  
  39.                 <artifactId>cargo-maven2-plugin</artifactId>  
  40.                 <version>1.2.3</version>  
  41.                 <configuration>  
  42.                     <container>  
  43.                         <containerId>tomcat7x</containerId>  
  44.                         <home>D:\apache-tomcat-7.0.29</home>  
  45.                     </container>  
  46.                     <configuration>  
  47.                         <type>standalone</type>  
  48.                         <home>${project.build.directory}/tomcat7.0.29</home>  
  49.                         <properties>  
  50.                             <cargo.jvmargs>  
  51.                                 -Xdebug  
  52.                                 -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787  
  53.                             </cargo.jvmargs>  
  54.                         </properties>  
  55.                     </configuration>  
  56.                 </configuration>  
  57.                 <executions>  
  58.                     <execution>  
  59.                         <id>cargo-run</id>  
  60.                         <phase>pre-integration-test</phase>  
  61.                         <goals>  
  62.                             <goal>run</goal>  
  63.                         </goals>  
  64.                     </execution>  
  65.                 </executions>  
  66.             </plugin>  
  67.   
  68.         </plugins>  
  69.   
  70.     </build>  
  71.   
  72. </project>  

这里主要是对maven-war-plugin和cargo-maven2-plugin这2个插件进行了配置,以起到聚合war,以及通过cargo启动容器的作用 

关于多war聚合,以及cargo,见另外2篇博客:http://kyfxbl.iteye.com/blog/1678121、http://kyfxbl.iteye.com/blog/1677608 

七、启动构建 

在task-aggregator目录下,执行mvn clean deploy或者mvn clean install,就可启动整个构建过程,并将容器启动起来,跑最终生成的war包 

  • 大小: 5.6 KB
  • 大小: 7.5 KB
  • 大小: 84.6 KB
  • 大小: 21.2 KB
  • 大小: 12.8 KB
  • 大小: 33.5 KB
  • 大小: 69.9 KB


最近在学习Maven,把一个开源的项目改成maven管理,期间使用到了多项目,从网上查阅了一些资料,主要参考的是http://kyfxbl.iteye.com/blog/1680045,在此把自己的一些心得体会写出来,供大家学习交流。

关于maven的安装,在此就不进行阐述,请参考网上其他教程。

本实例由4个项目组成,其中,aggregator是父工程,同时承担聚合模块和父模块的作用,没有实际代码和资源文件;open-plagform-common是公共的java工程;open-platfor-web是公共的web文件,主要包括css、js等;open-bug-m是最终要发布的应用,形成war包。

一、建立一个Maven工程:aggregator

/aggregator

   /src/main/java

   /src/test/java

   pom.xml

 

 

此工程主要是父模块,聚合其他工程,没有实际代码和资源文件,最主要的是pom.xml文件,其主要内容如下:

Xml代码   收藏代码
  1. <modelVersion>4.0.0</modelVersion>  
  2.   <groupId>cn.jess.platform</groupId>  
  3.   <artifactId>aggregator</artifactId>  
  4.   <version>0.0.1-SNAPSHOT</version>  
  5. <!-- 因为是父工程 ,因此此处的packaging必须为pom -->  
  6.   <packaging>pom</packaging>  
  7.   <name>aggregator</name>  
  8.     
  9.   <modules>    
  10.     <module>../open-platform-common</module>    
  11.     <module>../open-platform-web</module>    
  12.     <module>../open-bug-m</module>  
  13.   </modules>  
  14.     
  15.   <!-- 配置部署的远程仓库 -->    
  16.   <distributionManagement>    
  17.     <snapshotRepository>    
  18.       <id>nexus-snapshots</id>    
  19.       <name>nexus distribution snapshot repository</name>    
  20.       <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>    
  21.     </snapshotRepository>    
  22.   </distributionManagement>  
  23.     
  24.   <build>    
  25.      <pluginManagement>    
  26.        <plugins>    
  27.   
  28.              <plugin>    
  29.                  <groupId>org.apache.maven.plugins</groupId>    
  30.                  <artifactId>maven-resources-plugin</artifactId>    
  31.                  <version>2.6</version>    
  32.                  <configuration>    
  33.                      <encoding>UTF-8</encoding>    
  34.                  </configuration>    
  35.              </plugin>    
  36.   
  37.              <plugin>    
  38.                  <groupId>org.apache.maven.plugins</groupId>    
  39.                  <artifactId>maven-compiler-plugin</artifactId>    
  40.                  <version>2.5.1</version>    
  41.                  <configuration>    
  42.                      <encoding>UTF-8</encoding>  
  43.                      <source>1.6</source>  
  44.                      <target>1.6</target>    
  45.                  </configuration>    
  46.              </plugin>    
  47.   
  48.          </plugins>    
  49.      </pluginManagement>    
  50.  </build>    
  51.     
  52.  <dependencyManagement>    
  53.   
  54.      <dependencies>    
  55.   
  56.          <dependency>    
  57.              <groupId>com.sun</groupId>    
  58.              <artifactId>tools</artifactId>    
  59.              <version>1.6.0</version>    
  60.              <scope>system</scope>    
  61.              <systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>    
  62.          </dependency>    
  63.   
  64.      </dependencies>    
  65.   
  66.  </dependencyManagement>  

    二、建立一个Maven工程:open-platform-common

 

此工程主要是项目中使用到的公共java类库,pom文件主要内容如下:

 

Xml代码   收藏代码
  1. <!-- 由于存在parent工程,因此groupId和version可以省略,直接使用parent工程-->  
  2.   <modelVersion>4.0.0</modelVersion>  
  3.   <artifactId>open-platform-common</artifactId>  
  4.  <!-- 因为此工程要发布到webapp的lib目录下,因此为jar(不知道这样解释对否?) -->  
  5.  <packaging>jar</packaging>  
  6.   <properties>  
  7.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  8.   </properties>    
  9.     <!-- 指定Maven仓库 -->  
  10.     <repositories>  
  11.         <!-- my的maven仓库 -->  
  12.         <repository>  
  13.             <id>myRepository</id>  
  14.             <name>local private nexus</name>  
  15.             <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>  
  16.             <releases>  
  17.                 <enabled>true</enabled>  
  18.             </releases>  
  19.             <snapshots>  
  20.                 <enabled>true</enabled>  
  21.             </snapshots>  
  22.         </repository>  
  23.     </repositories>  
  24.   <!-- 指定maven plugin仓库 -->  
  25.     <pluginRepositories>  
  26.         <!-- oschina的maven plugin仓库 -->  
  27.         <pluginRepository>  
  28.             <id>myPluginRepository</id>  
  29.             <name>local private nexus</name>  
  30.             <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>  
  31.             <releases>  
  32.                 <enabled>true</enabled>  
  33.             </releases>  
  34.             <snapshots>  
  35.                 <enabled>false</enabled>  
  36.             </snapshots>  
  37.         </pluginRepository>  
  38.     </pluginRepositories>  
  39.   <dependencies>  
  40.         <!-- 此处的类库根据自己的需要进行添加 -->  
  41.   </dependencies>  
  42.   <!-- 用来指定父工程-->  
  43.   <parent>  
  44.     <groupId>cn.jess.platform</groupId>  
  45.     <artifactId>aggregator</artifactId>  
  46.     <version>0.0.1-SNAPSHOT</version>  
  47.     <relativePath>../aggregator</relativePath>  
  48.   </parent>  

    三、建立一个Maven工程:open-platform-web

    此工程主要是项目中使用到的公共web文件,pom文件主要内容如下:

 

Xml代码   收藏代码
  1. <!-- 由于存在parent工程,因此groupId和version可以省略,直接使用parent工程-->  
  2.   <modelVersion>4.0.0</modelVersion>  
  3.   <artifactId>open-platform-web</artifactId>  
  4. <!-- 因为此工程要发布到webapp应用的根目录下,因此为war(不知道这样解释对否?) -->  
  5.   <packaging>war<ng>  
  6.   <properties>  
  7.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  8.   </properties>    
  9.     <!-- 指定Maven仓库 -->  
  10.     <repositories>  
  11.         <!-- my的maven仓库 -->  
  12.         <repository>  
  13.             <id>myRepository</id>  
  14.             <name>local private nexus</name>  
  15.             <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>  
  16.             <releases>  
  17.                 <enabled>true</enabled>  
  18.             </releases>  
  19.             <snapshots>  
  20.                 <enabled>true</enabled>  
  21.             </snapshots>  
  22.         </repository>  
  23.     </repositories>  
  24.   <!-- 指定maven plugin仓库 -->  
  25.     <pluginRepositories>  
  26.         <!-- oschina的maven plugin仓库 -->  
  27.         <pluginRepository>  
  28.             <id>myPluginRepository</id>  
  29.             <name>local private nexus</name>  
  30.             <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>  
  31.             <releases>  
  32.                 <enabled>true</enabled>  
  33.             </releases>  
  34.             <snapshots>  
  35.                 <enabled>false</enabled>  
  36.             </snapshots>  
  37.         </pluginRepository>  
  38.     </pluginRepositories>  
  39.     
  40.   <parent>  
  41.     <groupId>cn.jess.platform</groupId>  
  42.     <artifactId>aggregator</artifactId>  
  43.     <version>0.0.1-SNAPSHOT</version>  
  44.     <relativePath>../aggregator</relativePath>  
  45.   </parent>  
  46. </project>  

    注意:此工程的WEB-INF目录下必须包含web.xml文件,否则在执行mvn时会报错

    四、建立一个Maven工程:open-bug-m:

此工程是最终要发布的应用,其依赖于open-platform-common和open-platform-web,因此在pom文件中要加入这两个工程的依赖,pom文件内容如下所示:

 

Xml代码   收藏代码
  1. <groupId>open-bug-m</groupId>  
  2.   <artifactId>open-bug-m</artifactId>  
  3.   <packaging>war</packaging>  
  4.   <name/>  
  5.   <description/>  
  6.   <properties>  
  7.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  8.   </properties>  
  9.   <parent>  
  10.     <groupId>cn.jess.platform</groupId>  
  11.     <artifactId>aggregator</artifactId>  
  12.     <version>0.0.1-SNAPSHOT</version>  
  13.     <relativePath>../aggregator</relativePath>  
  14.   </parent>   
  15.     <!-- 指定Maven仓库 -->  
  16.     <repositories>  
  17.         <!-- my的maven仓库 -->  
  18.         <repository>  
  19.             <id>myRepository</id>  
  20.             <name>local private nexus</name>  
  21.             <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>  
  22.             <releases>  
  23.                 <enabled>true</enabled>  
  24.             </releases>  
  25.             <snapshots>  
  26.                 <enabled>true</enabled>  
  27.             </snapshots>  
  28.         </repository>  
  29.     </repositories>  
  30.   <!-- 指定maven plugin仓库 -->  
  31.     <pluginRepositories>  
  32.         <!-- oschina的maven plugin仓库 -->  
  33.         <pluginRepository>  
  34.             <id>myPluginRepository</id>  
  35.             <name>local private nexus</name>  
  36.             <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>  
  37.             <releases>  
  38.                 <enabled>true</enabled>  
  39.             </releases>  
  40.             <snapshots>  
  41.                 <enabled>false</enabled>  
  42.             </snapshots>  
  43.         </pluginRepository>  
  44.     </pluginRepositories>  
  45.   <dependencies>  
  46.     <dependency>  
  47.       <groupId>cn.jess.platform</groupId>  
  48.       <artifactId>open-platform-common</artifactId>  
  49.       <version>0.0.1-SNAPSHOT</version>  
  50.       <type>jar</type>  
  51.     </dependency>  
  52.     <dependency>  
  53.       <groupId>cn.jess.platform</groupId>  
  54.       <artifactId>open-platform-web</artifactId>  
  55.       <version>0.0.1-SNAPSHOT</version>  
  56.       <type>war</type>  
  57.     </dependency>        
  58.     <!-- 此处的类库根据自己的需要进行添加 -->  
  59.   
  60.       
  61.   </dependencies>  
  62.   <build>  
  63.     <finalName>open-bug</finalName>  
  64.     <plugins>  
  65.       <plugin>    
  66.           <groupId>org.apache.maven.plugins</groupId>    
  67.           <artifactId>maven-war-plugin</artifactId>  
  68.           <version>2.3</version>    
  69.           <configuration>    
  70.              <packagingExcludes>WEB-INF/web.xml</packagingExcludes>      
  71.              <overlays>    
  72.                 <overlay>    
  73.                   <groupId>cn.jess.platform</groupId>    
  74.                   <artifactId>open-platform-web</artifactId>    
  75.                 </overlay>    
  76.              </overlays>    
  77.           </configuration>    
  78.       </plugin>    
  79.       <plugin>    
  80.         <groupId>org.codehaus.cargo</groupId>    
  81.         <artifactId>cargo-maven2-plugin</artifactId>    
  82.         <version>1.2.3</version>    
  83.         <configuration>    
  84.           <container>    
  85.             <containerId>tomcat7x</containerId>    
  86.             <home>F:\apache-tomcat-7.0.42(x64)</home>    
  87.           </container>    
  88.           <configuration>    
  89.             <type>existing</type>    
  90.             <home>F:\apache-tomcat-7.0.42(x64)</home>    
  91.             <properties>    
  92.               <cargo.jvmargs>    
  93.                   -Xdebug                    -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787    
  94.               </cargo.jvmargs>    
  95.             </properties>    
  96.           </configuration>    
  97.         </configuration>    
  98.         <executions>    
  99.           <execution>    
  100.              <id>cargo-run</id>    
  101.              <phase>pre-integration-test</phase>    
  102.              <goals>    
  103.                  <goal>run</goal>    
  104.              </goals>    
  105.           </execution>    
  106.         </executions>    
  107.     </plugin>   
  108.     </plugins>  
  109.   </build>  

    关于maven-war-plugin和cargo-maven2-plugin的使用方法请参考网上其他使用教程。

所有上述四个工程准备就绪后,执行mvn install就可对工程项目进行部署。










评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值