将不同的maven web项目组合到一个项目中

时间:2012-12-31 10:59:39

标签: javascript maven

我希望将超过3个maven项目(基于HTML,javascript和CSS)合并为一个。我的主项目使用其他项目的依赖项。那么,如何在不改变这些依赖关系的情况下构建单个项目呢?

2 个答案:

答案 0 :(得分:3)

假设您有一个多模块项目:

  1. mysite:父母pom模块。
  2. mysite-core:一个ja​​va模块
  3. mysite-web:网络资源模块(javascript,html,...)
  4. mysite-webapp:战争模块
  5. mysitepackaging pom并包含其他3 modules

    <groupId>mysite</groupId>
    <artifactId>mysite</artifactId>
    <packaging>pom</packaging>
    <modules>
       <module>../mysite-core</module>
       <module>../mysite-web</module>
       <module>../mysite-webapp</module>
    </modules>
    

    mysite-core使用标准jar packaging

    <parent>
       <artifactId>mysite</artifactId>
       <groupId>mysite</groupId>
       <relativePath>../mysite/</relativePath>
    </parent>
    <groupId>mysite</groupId>
    <artifactId>mysite-core</artifactId>
    

    mysite-web类似:

    ...
    <artifactId>mysite-web</artifactId>
    

    mysite-webapp包括java和web资源模块作为依赖项:

    ...
    <artifactId>mysite-webapp</artifactId>
    <packaging>war</packaging>
    
    <dependency>
       <groupId>mysite</groupId>
       <artifactId>mysite-core</artifactId>
    </dependency>
    <dependency>
       <groupId>mysite</groupId>
       <artifactId>mysite-web</artifactId>
    </dependency>
    

    使用overlays中的maven-war-plugin属性,您可以将资源添加到战争中:

    <overlays>
       <overlay>
          <groupId>mysite</groupId>
          <artifactId>mysite-web</artifactId>
          <type>jar</type>
       </overlay>
    </overlays>
    

    注意:最好有flat project layout,例如:

      • parent pom module
      • java pom module
      • java-1 jar模块
      • java-2 jar模块
      • 网络资源jar模块
      • 战争模块

    而不是分层布局:

      • 父pom模块
        • java pom module
        • java-1 jar模块
        • java-2 jar模块
        • 网络资源jar模块
        • 战争模块

    我注意到像Eclipse这样的工具不喜欢层次结构(缓慢甚至无限的构建)。

答案 1 :(得分:-1)

使用Maven模块。这里有大量文档:

http://maven.apache.org/guides/mini/guide-multiple-modules.html

相关问题