maven - 在EAR打包时不要在/ lib之外复制项目jar

时间:2013-10-24 05:57:31

标签: maven maven-3 maven-ear-plugin

包装EAR时会发生这种情况

我的pom.xml打包了ear文件,它应该包含projectA.jar文件和/ lib文件夹外的projectB.war。显然,projectA.jar文件正在/ lib文件夹里面,这不应该是。我有我的application.xml,它告诉我们这两个项目应该在lib之外。

问题:我如何指示maven不将projectA.jar捆绑在/ lib文件夹中,而是将其捆绑在/ lib文件夹之外?

我的EAR结构应该是:

  

MyWebEAR

\lib
\META-INF
projectA.jar
ProjectB.war

下面是我的pom。

<dependencies>
    <dependency>
        <groupId>com.xxx.sms</groupId> 
        <artifactId>projectA</artifactId> 
        <version>1.0-SNAPSHOT</version>             
    </dependency>
    <dependency>
        <groupId>com.xxx</groupId>
        <artifactId>projectB</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>war</type>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-ear-plugin</artifactId>
            <configuration>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <earSourceDirectory>${basedir}</earSourceDirectory>
                <earSourceIncludes>META-INF/*</earSourceIncludes>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
                <generateApplicationXml>false</generateApplicationXml>
                <applicationXML>${basedir}/META-INF/application.xml</applicationXML>
            </configuration>
        </plugin>
    </plugins>
    <finalName>MyWebEAR</finalName>
</build>

感谢您的时间。

2 个答案:

答案 0 :(得分:5)

您需要在maven-ear-plugin jarModule的{​​{1}}部分专门为projectA依赖项定义modules配置,并明确设置jar放置的位置。< / p>

所以你的POM会是:

configuration

<plugin> <artifactId>maven-ear-plugin</artifactId> <configuration> <defaultLibBundleDir>lib</defaultLibBundleDir> <earSourceDirectory>${basedir}</earSourceDirectory> <earSourceIncludes>META-INF/*</earSourceIncludes> <archive> <manifest> <addClasspath>true</addClasspath> </manifest> </archive> <generateApplicationXml>false</generateApplicationXml> <applicationXML>${basedir}/META-INF/application.xml</applicationXML> <modules> <jarModule> <groupId>com.xxx.sms</groupId> <artifactId>projectA</artifactId> <bundleDir>/</bundleDir> </jarModule> </modules> </configuration> </plugin> 中的值(/)告诉maven-ear-plugin将projectA的jar放在ear的根文件夹中,而不是lib的默认位置。

您可以在插件文档中查看详细信息: http://maven.apache.org/plugins/maven-ear-plugin/examples/customizing-module-location.html

答案 1 :(得分:0)

我的项目遇到了同样的问题。

In my case, I was using an MDB so it was needed to be declared as  <**ejbModule**> instead of jarModule. I also had to declare my dependency as of type ejb to be picked up Jboss (6.4):

<dependency>
    <groupId>ab.cd</groupId>
    <artifactId>mdb-publisher</artifactId>
    <version>xxx-SNAPSHOT</version>
   <type>**ejb**</type>
</dependency>