application.xml不存在.maven EAR构建期间出错

ara*_*ind 4 java xml maven

我正在尝试构建一个内部有两个war文件的ear项目.在构建EAR时,我收到错误,因为"application.xml不存在".但我已将application.xml放在项目META INF文件夹中.请在下面找到代码.并建议解决方案来解决这个问题.

下面是我的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>
Run Code Online (Sandbox Code Playgroud)

下面是我的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>
Run Code Online (Sandbox Code Playgroud)

打开此图像以获取项目结构.

项目结构

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
Run Code Online (Sandbox Code Playgroud)

dav*_*xxx 5

1)application.xml自JavaEE 5.0起,不再需要EAR中的文件

2)在maven-ear-plugin配置中,您不生成application.xml文件:

 <generateApplicationXml>false</generateApplicationXml>
Run Code Online (Sandbox Code Playgroud)

并指定application.xml此处的位置: <applicationXML>src/main/application/META-INF/application.xml</applicationXML>

因此,您应确保该application.xml文件位于以下位置:src/main/application/META-INF

3)最简单的是不使用 <generateApplicationXml>false</generateApplicationXml>.它可以避免您声明application.xml文件.