2013-10-24 53 views
1

這同時包裝行家 - 不是抄襲項目罐子外面/ lib目錄,而EAR包裝

我的pom.xml是包裝EAR文件,它應該包括外projectA.jar文件和projectB.war的EAR發生/ lib文件夾。顯然,projectA.jar文件將進入/ lib文件夾中,這不應該是。我有我的application.xml,它告訴這兩個項目應該在lib之外。

問題:我如何指示maven不要將projectA.jar捆綁到/ lib文件夾中,而是將它捆綁到/ lib文件夾之外?

我的耳朵結構應該是:

MyWebEAR

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

下面是我的聚甲醛。

<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> 

謝謝你的時間。

回答

4

您需要在projectA依賴關係的maven-ear-plugin configurationmodules部分中專門定義jarModule配置,並明確設置放置jar的位置。

所以,你的POM是:

<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> 

bundleDir值(/)告訴Maven的入耳式插件放置了projectA的罐子在耳朵的根文件夾,而不是11b的默認位置。

你可以看到這個細節在這裏的插件文件中: http://maven.apache.org/plugins/maven-ear-plugin/examples/customizing-module-location.html

+0

謝謝。乾杯。 –

+0

不客氣。很高興它解決了你的問題。 – DB5

+0

是的。它解決了。 –

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>