2012-08-23 81 views
6

我一直在關注maven-ear-plugin站點上的示例shows how to add third-party libraries to the generated application.xml。但是,它並沒有像我期望的那樣工作。類似地,web模塊contextRoot被忽略。maven-ear-plugin不包括jarModule到application.xml中

根據documentation我試圖做的應該是完全可能的。

Web模塊的上下文根可能會使用 上下文根參數進行定製。

請注意,第三方庫(即JarModule)不 包含在生成的application.xml(僅EJB客戶端應該是 包含在Java入口)。但是,通過指定 includeInApplicationXml標誌可以將jar依賴項包含在生成的application.xml中的 。

當它在我的application.xml中執行構建時,我有以下輸出。

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE application PUBLIC 
    "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" 
    "http://java.sun.com/dtd/application_1_3.dtd"> 
<application> 
    <display-name>MyApp.EAR</display-name> 
    <module> 
    <ejb>MyApp.jar</ejb> 
    </module> 
    <module> 
    <web> 
     <web-uri>MyApp.war</web-uri> 
     <context-root>/MyApp.Web</context-root> 
    </web> 
    </module> 
</application> 

從以下maven配置(pom.xml)。

... 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.blah</groupId> 
<artifactId>MyApp.EAR</artifactId> 
<version>1.0</version> 
<packaging>ear</packaging> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>maven-ear-plugin</groupId> 
      <artifactId>maven-ear-plugin</artifactId> 
      <version>2.7</version> 
      <configuration> 
       <applicationName>MyApp</applicationName> 
       <modules> 
        <ejbModule> 
         <groupId>com.blah</groupId> 
         <artifactId>MyApp.EJB</artifactId> 
        </ejbModule> 
        <webModule> 
         <groupId>com.blah</groupId> 
         <artifactId>MyApp.Web</artifactId> 
         <contextRoot>MyApp</contextRoot> 
        </webModule> 
        <jarModule> 
         <groupId>org.slf4j</groupId> 
         <artifactId>slf4j-simple</artifactId> 
         <includeLibInApplicationXml>true</includeLibInApplicationXml> 
        </jarModule> 
       </modules> 
       <archive> 
        <manifestEntries> 
         <WebLogic-Application-Version>${weblogic.version}</WebLogic-Application-Version> 
        </manifestEntries> 
       </archive> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

<dependencies> 
    <!-- web and ejb modules --> 
    <dependency> 
     <groupId>com.blah</groupId> 
     <artifactId>MyApp.EJB</artifactId> 
     <version>1.0</version> 
     <type>ejb</type> 
    </dependency> 
    <dependency> 
     <groupId>com.blah</groupId> 
     <artifactId>MyApp.Web</artifactId> 
     <version>1.0</version> 
     <type>war</type> 
    </dependency> 
</dependencies> 
... 

很明顯,application.xml並不是按照我的意圖生成的。

  1. 提供的contextRoot在application.xml中不正確,而是輸出MyApp.Web的默認名稱而不是指定的MyApp。
  2. 指定的org.slf4j jarModule完全缺少application.xml。

我在做什麼錯?

從Maven進行調試如下所示。

[DEBUG] ----------------------------------------------------------------------- 
[DEBUG] Goal:   org.apache.maven.plugins:maven-ear-plugin:2.4.2:generate-application-xml (default-generate-application-xml) 
[DEBUG] Style:   Regular 
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <description>${project.description}</description> 
    <displayName>${project.artifactId}</displayName> 
    <encoding default-value="UTF-8"/> 
    <generatedDescriptorLocation>${project.build.directory}</generatedDescriptorLocation> 
    <includeLibInApplicationXml default-value="false"/> 
    <project>${project}</project> 
    <version default-value="1.3"/> 
    <workDirectory>${project.build.directory}/${project.build.finalName}</workDirectory> 
</configuration> 

P.S.我嘗試創建maven-ear-plugin標籤,但它不會讓我失去信譽!如果有人可以創造,我會很感激。

+0

這似乎完全忽略了我的配置。任何想法爲什麼? – mrswadge

回答

9

我按照慣例將其解決了,這是用戶錯誤。

奇怪的是,它正在生產EAR文件非常正確,即使我的插件配置不正確。

我取代...

<groupId>maven-ear-plugin</groupId> 
<artifactId>maven-ear-plugin</artifactId> 

與...

<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-ear-plugin</artifactId> 

再改......

<includeLibInApplicationXml>true</includeLibInApplicationXml> 

到...

<includeInApplicationXml>true</includeInApplicationXml> 

然後突然它做了我原本打算做的事情。

我的最終pom.xml看起來像這樣,因爲我決定我想要所有jar被自動包含。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.blah</groupId> 
    <artifactId>MyApp.EAR</artifactId> 
    <version>1.0</version> 
    <packaging>ear</packaging> 

    <properties> 
     <weblogic.version>10.3</weblogic.version> 
     <weblogic.version.minor>${weblogic.version}.4</weblogic.version.minor> 
     <weblogic.host>***</weblogic.host> 
     <weblogic.port>***</weblogic.port> 
     <weblogic.username>***</weblogic.username> 
     <weblogic.password>***</weblogic.password> 
    </properties> 

    <build> 
     <finalName>MyApp</finalName> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-ear-plugin</artifactId> 
       <version>2.7</version> 
       <configuration> 
        <applicationName>MyApp</applicationName> 
      <includeLibInApplicationXml>true</includeLibInApplicationXml> 
        <modules> 
         <ejbModule> 
          <groupId>com.blah</groupId> 
          <artifactId>MyApp.EJB</artifactId> 
         </ejbModule> 
         <webModule> 
          <groupId>com.blah</groupId> 
          <artifactId>MyApp.Web</artifactId> 
          <contextRoot>MyApp</contextRoot> 
         </webModule> 
        </modules> 
        <archive> 
         <manifestEntries> 
          <WebLogic-Application-Version>${weblogic.version}</WebLogic-Application-Version> 
         </manifestEntries> 
        </archive> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>com.oracle.weblogic</groupId> 
       <artifactId>weblogic-maven-plugin</artifactId> 
       <version>10.3.4</version> 
       <configuration> 
        <adminurl>t3://${weblogic.host}:${weblogic.port}</adminurl> 
        <user>${weblogic.username}</user> 
        <password>${weblogic.password}</password> 
        <upload>true</upload> 
        <action>deploy</action> 
        <remote>false</remote> 
        <verbose>true</verbose> 
        <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source> 
        <name>${project.build.finalName}</name> 
       </configuration> 
       <executions> 
        <execution> 
         <phase>install</phase> 
         <goals> 
          <goal>deploy</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 

     </plugins> 

     <pluginManagement> 
      <plugins> 
       <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> 
       <plugin> 
        <groupId>org.eclipse.m2e</groupId> 
        <artifactId>lifecycle-mapping</artifactId> 
        <version>1.0.0</version> 
        <configuration> 
         <lifecycleMappingMetadata> 
          <pluginExecutions> 
           <pluginExecution> 
            <pluginExecutionFilter> 
             <groupId>org.apache.maven.plugins</groupId> 
             <artifactId>maven-ear-plugin</artifactId> 
             <versionRange>[2.7,)</versionRange> 
             <goals> 
              <goal>generate-application-xml</goal> 
             </goals> 
            </pluginExecutionFilter> 
            <action> 
             <ignore></ignore> 
            </action> 
           </pluginExecution> 
          </pluginExecutions> 
         </lifecycleMappingMetadata> 
        </configuration> 
       </plugin> 
      </plugins> 
     </pluginManagement> 
    </build> 

    <dependencies> 
    <dependency> 
     <groupId>com.blah</groupId> 
     <artifactId>MyApp.EJB</artifactId> 
     <version>1.0</version> 
     <type>ejb</type> 
    </dependency> 
    <dependency> 
     <groupId>com.blah</groupId> 
     <artifactId>MyApp.Web</artifactId> 
     <version>1.0</version> 
     <type>war</type> 
    </dependency> 
    </dependencies> 
</project> 
+0

您的最終示例不再使用'jarModule'。你有問題嗎? –

+0

@SérgioMichels不,這與問題無關。 – mrswadge

1

非常感謝,幾個小時以來一直在尋找這個問題的解決方案。 :) 如果這可能也會幫助其他人,那麼請廣告我的朋友。

<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <parent> 
     <artifactId>appletree.be-multi</artifactId> 
     <groupId>be.appletree</groupId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 
    <modelVersion>4.0.0</modelVersion> 

    <artifactId>appletree.be-ear</artifactId> 
    <packaging>ear</packaging> 

    <dependencies> 


     <dependency> 
      <groupId>be.appletree</groupId> 
      <artifactId>appletree.be-domain</artifactId> 
      <version>1.0-SNAPSHOT</version> 
      <type>jar</type> 
     </dependency> 

     <dependency> 
      <groupId>be.appletree</groupId> 
      <artifactId>appletree.be-ejb</artifactId> 
      <version>1.0-SNAPSHOT</version> 
      <type>ejb</type> 
     </dependency> 

     <dependency> 
      <groupId>be.appletree</groupId> 
      <artifactId>appletree.be-web</artifactId> 
      <version>1.0-SNAPSHOT</version> 
      <type>war</type> 
     </dependency> 

    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-ear-plugin</artifactId> 
       <version>2.8</version> 
       <configuration> 
        <modules> 
         <jarModule> 
          <groupId>be.appletree</groupId> 
          <artifactId>appletree.be-domain</artifactId> 
          <includeInApplicationXml>true</includeInApplicationXml> 
         </jarModule> 
         <webModule> 
          <groupId>be.appletree</groupId> 
          <artifactId>appletree.be-web</artifactId> 
         </webModule> 
         <ejbModule> 
          <groupId>be.appletree</groupId> 
          <artifactId>appletree.be-ejb</artifactId> 
         </ejbModule> 
        </modules> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

</project>