Maven错误:工件不是项目的依赖项

时间:2017-09-05 12:26:51

标签: java maven

   [ERROR] Failed to execute goal org.apache.maven.plugins:maven-ear-
    plugin:2.6:generate-application-xml (default-generate-application-xml) 
    on project itaras-ear: Artifact[war:org.apache.maven.plugins:maven-war-
    plugin] is not a dependency of the project. 

首先,我为我的应用程序构建了一个WAR文件。现在我正在构建我的EAR文件,该文件应该具有WAR作为依赖。

当我收到上述错误消息时,我使用m2e插件运行了ITARAS-EAR模块。

模块WAR的pom.xml在下面。

  <parent>
   <groupId>itaras</groupId>
   <artifactId>itaras</artifactId>
   <version>1.0-SNAPSHOT</version>
  </parent>
<groupId>itaras-war</groupId>
 <artifactId>itaras-war</artifactId>
 <packaging>war</packaging>
  <build>
<plugins>
  <plugin>            
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
   <configuration>
       <webXml>src\main\webapp\WEB-INF\web.xml</webXml>        
      </configuration>
     </plugin>
     </plugins>
       </build>
    </project>

模块EAR的pom.xml就在这里。

  <parent>
  <groupId>itaras</groupId>
  <artifactId>itaras</artifactId>
  <version>1.0-SNAPSHOT</version>
  </parent>
 <artifactId>itaras-ear</artifactId>
 <packaging>ear</packaging>
  <dependencies>
    <dependency>
        <groupId>itaras-war</groupId>
        <artifactId>itaras-war</artifactId>

        <type>war</type>
        <version>${project.version}</version>
    </dependency>

   </dependencies>
     <build>
     <plugins>
      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-ear-plugin</artifactId>
        <version>2.6</version>
        <configuration>
              <defaultLibBundleDir>lib</defaultLibBundleDir>
            <applicationXML>src/main/application/META-
        INF/application.xml</applicationXML>
         </configuration>
    </plugin>
     </plugins>
    </build>
    <groupId>itaras-ear</groupId>
     </project>

提前致谢。如果我从根本上走错了,请纠正我:)

1 个答案:

答案 0 :(得分:3)

你的战争项目有2个groupIds

<parent>
   <groupId>itaras</groupId>
   <artifactId>itaras</artifactId>
   <version>1.0-SNAPSHOT</version>
  </parent>
*** <groupId>itaras-war</groupId> ****
<artifactId>itaras-war</artifactId>
<packaging>war</packaging>

删除groupId并允许它从父级中选择它的groupId。仅从父级指定artifactId,version和groupId。

然后你对你耳朵项目中战争的依赖是:

<dependencies>
  <dependency>
      <groupId>itaras</groupId>
      <artifactId>itaras-war</artifactId>
      <type>war</type>
      <version>${project.version}</version>
  </dependency>
</dependencies>