2016-12-24 34 views
4

我正在嘗試構建一個帶有兩個內部war文件的ear項目。在構建EAR時,我收到錯誤,因爲「application.xml不存在」。但我已將application.xml放置在項目META INF文件夾中。請找到下面的代碼。並提出解決方案來解決這個問題。application.xml不存在。在Maven EAR構建中出現錯誤

下面是我的pom.xml

<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>au.com.mercury</groupId> 
    <artifactId>ReplenishmentR4</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>ear</packaging> 
    <build> 
    <plugins> 
    <plugin> 
     <artifactId>maven-ear-plugin</artifactId> 
     <version>2.6</version> 
     <configuration> 
     <applicationXML>src/main/application/META-INF/application.xml</applicationXML> 
     <generateApplicationXml>false</generateApplicationXml> 
     <encoding>UTF-8</encoding> 
     <defaultLibBundleDir>lib/</defaultLibBundleDir> 
     <filtering>true</filtering> 
     <modules> 
      <webModule> 
      <groupId>au.com.mercury</groupId> 
      <artifactId>Replenishment</artifactId> 
      <bundleFileName>Replenishment.war</bundleFileName> 
      </webModule> 
      <webModule> 
      <groupId>au.com.mercury</groupId> 
      <artifactId>ReplenishmentR3</artifactId> 
      <bundleFileName>ReplenishmentR3.war</bundleFileName> 
      </webModule> 
     </modules> 
     </configuration> 
    </plugin> 
    <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.1</version> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 
    </plugins> 
    <finalName>ReplenishmentR4</finalName> 
</build> 

<dependencies> 

    <dependency> 
    <groupId>au.com.mercury</groupId> 
    <artifactId>Replenishment</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <type>war</type> 
    </dependency> 
    <dependency> 
    <groupId>au.com.mercury</groupId> 
    <artifactId>ReplenishmentR3</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <type>war</type> 
    </dependency> 
    </dependencies> 
</project> 

下面是我的application.xml

<?xml version="1.0" encoding="UTF-8"?> 
<application> 
    <module> 
    <web> 
     <web-uri>Replenishment.war</web-uri> 
     <context-root>/Replenishment</context-root> 
    </web> 
    </module> 
    <module> 
    <web> 
     <web-uri>ReplenishmentR3.war</web-uri> 
     <context-root>/ReplenishmentR2</context-root> 
    </web> 
    </module> 
</application> 

打開該圖片的項目結構。

Project structure

Maven構建控制檯錯誤:

[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building ReplenishmentR4 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[WARNING] The POM for au.com.woolworths.mercury:ReplenishmentR3:war:0.0.1-SNAPSHOT is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details 
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ ReplenishmentR4 --- 
[INFO] Deleting C:\Users\xagh9\workspace\ReplenishmentR4\target 
[INFO] 
[INFO] --- maven-ear-plugin:2.6:generate-application-xml (default-generate-application-xml) @ ReplenishmentR4 --- 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ReplenishmentR4 --- 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory C:\Users\xagh9\workspace\ReplenishmentR4\src\main\resources 
[INFO] 
[INFO] --- maven-ear-plugin:2.6:ear (default-ear) @ ReplenishmentR4 --- 
[INFO] Copying artifact[war:au.com.mercury:Replenishment:0.0.1-SNAPSHOT] to[Replenishment.war] 
[INFO] Copying artifact[war:au.com.mercury:ReplenishmentR3:0.0.1-SNAPSHOT] to[ReplenishmentR3.war] 
[INFO] Copy ear sources to C:\Users\xagh9\workspace\ReplenishmentR4\target\ReplenishmentR4 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 6.177 s 
[INFO] Finished at: 2016-12-24T22:33:03+11:00 
[INFO] Final Memory: 12M/164M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-ear-plugin:2.6:ear (default-ear) on project ReplenishmentR4: Deployment descriptor: C:\Users\xagh9\workspace\ReplenishmentR4\target\ReplenishmentR4\META-INF\application.xml does not exist. -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 
+0

圖片上的位置讓我覺得你配置了錯誤的位置。除此之外,你應該遵循約定......'src/main/resources/META-INF/application.xml'而不是'ear-resources/...'? – khmarbaise

+0

@khmarbaise ...你錯了。位置是** src/main/application/META-INF ** – aravind

回答

5

1)application.xml文件中的EAR不需要因爲JavaEE的5.0

2)不再在行家-EAR-插件配置,你不會生成application.xml文件:

<generateApplicationXml>false</generateApplicationXml> 

和指定的application.xml這裏的位置:最簡單的不使用<generateApplicationXml>false</generateApplicationXml>src/main/application/META-INF

3):<applicationXML>src/main/application/META-INF/application.xml</applicationXML>

所以,你應該確保application.xml文件是在這個位置。它避免了你聲明application.xml文件。

+0

嗨大衛,謝謝你的建議.. – aravind

+0

我把'application.xml'文件保存在這個位置:** src/main/application/META -INF **,它工作。非常感謝... :) – aravind

+0

嗨,歡迎您:) – davidxxx