多模块maven项目:使用着色工件生成EAR

时间:2015-12-17 10:39:06

标签: java maven ear maven-shade-plugin maven-ear-plugin

我有一个多模块项目,其中一个模块应该从其他模块工件中创建一个EAR。为了使事情变得更有趣,这些其他4个工件必须被阴影分为2个工件:

super-pom
|-- ear module
|-- ejb1
|-- ejb2
|-- web1
|-- web2

它创建的是包含ejb2阴影,web2阴影和ej1,web1的EAR(包含在阴影版本中!)。 奇怪的是,如果我在每个模块中手动运行maven,最后在耳模块中运行maven,我得到了我想要的东西。

我能弄清楚的是,超级巨蛋如何将这些文物偷偷带入EAR。事件maven package -X仅在清除步骤中列出正确的工件:

[DEBUG] Resolving artifact type mappings ...
[DEBUG] Initializing JBoss configuration if necessary ...
[DEBUG] Initializing ear execution context
[DEBUG] Resolving ear modules ...
[DEBUG] Resolving ear module[ejb:com.mycomp:ejb2]
[DEBUG] Resolving ear module[war:com.mycomp:web2]
[DEBUG] Resolving ear module[jar:org.jboss.seam:jboss-seam]
[INFO] Generating application.xml

一些简化的poms,从超级pom开始:

<artifactId>super-pom</artifactId>
<packaging>pom</packaging>
<modules>
    <module>ejb1</module>
    <module>web1</module>
    <module>ejb2</module>
    <module>web2</module>
    <module>ear</module>
</modules>

耳POM:

<artifactId>ear</artifactId>
<packaging>ear</packaging>
<parent>
    ...
    <artifactId>super-pom</artifactId>
    ...
</parent>

<dependencies>
    <dependency>
        ...
        <artifactId>ejb2</artifactId>
        <type>ejb</type>
        ...
    </dependency>
    <dependency>
        ...
        <artifactId>web2</artifactId>
        <type>ejb</type>
        ...
    </dependency>
    <!-- Little "trick" to avoid listing all shared deps from WAR. To use skinyWar, 
            deps to be shared via EAR/lib must be explicitly listed here. Including the 
            POM let's maven deal with this -->
    <dependency>
        ...
        <artifactId>web2</artifactId>
        <type>pom</type>
        ...
    </dependency>
</dependencies>

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <!-- Tell Maven we are using Java EE 6 -->
            <version>6</version>
            <defaultLibBundleDir>lib</defaultLibBundleDir>
            <!-- See maven docs; Necessary because we CAN'T have 2 jboss-seam.jars 
                in the same EAR -->
            <skinnyWars>true</skinnyWars>
            <initializeInOrder>true</initializeInOrder>
            <modules>
                <ejbModule>
                    <groupId>com.mycomp</groupId>
                    <artifactId>ejb2</artifactId>
                </ejbModule>
                <webModule>
                    <groupId>com.mycomp</groupId>
                    <artifactId>web2</artifactId>
                    <contextRoot>/</contextRoot>
                </webModule>

                <jarModule>
                    <groupId>org.jboss.seam</groupId>
                    <artifactId>jboss-seam</artifactId>
                    <includeInApplicationXml>true</includeInApplicationXml>
                    <bundleDir>/</bundleDir>
                </jarModule>
            </modules>
        </configuration>
    </plugin>
</plugins> 

EJB2-POM:

<artifactId>ejb2</artifactId>
<packaging>ejb</packaging>
<parent>
    ...
    <artifactId>super-pom</artifactId>
    ...
</parent>

<dependencies>
    <dependency>
        ...
        <artifactId>ejb1</artifactId>
        <type>ejb</type>
        ...
    </dependency>
</dependencies>

<plugins>
    ...
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.2</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
              <artifactSet>
                <includes>
                  <include>com.mycomp:ejb1</include>
                </includes>
              </artifactSet>
            </configuration>
          </execution>
        </executions>
    </plugin>
</plugins>

web2的-POM:

<artifactId>web2</artifactId>
<packaging>war</packaging>
<parent>
    ...
    <artifactId>super-pom</artifactId>
    ...
</parent>

<dependencies>
    <dependency>
        ...
        <artifactId>web1</artifactId>
        <type>war</type>
        ...
    </dependency>
</dependencies>

<plugins>
    ...
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.2</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
              <artifactSet>
                <includes>
                  <include>com.mycomp:web1</include>
                </includes>
              </artifactSet>
            </configuration>
          </execution>
        </executions>
    </plugin>
</plugins>

0 个答案:

没有答案