2017-07-27 72 views
0

我有以前与以下结构的工作,除了战争包装Maven项目,建立插件和Web应用程序/:Maven战争 - '包装'价值'战争'是无效的。聚合项目需要“POM”包装

Project structure 而下面父pom.xml的构建周期

<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <warName>${project.artifactId}</warName> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.8</version> 
       <executions> 
        <execution> 
         <id>install</id> 
         <phase>install</phase> 
         <goals> 
          <goal>sources</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-resources-plugin</artifactId> 
       <version>2.5</version> 
       <configuration> 
        <encoding>UTF-8</encoding> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.6.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
    <finalName>ConcertLiveCheck</finalName> 
</build> 

但是,每当我试图编译我的项目作为一战,我收到以下错误

'packaging' with value 'war' is invalid. Aggregator projects require 'pom' as packaging 

在此之前,我是编译为pom,没有maven war插件和每个maven模块正在编译正确的目标,并且我的项目正在运行。 但是,因为我打算在Web服务器上运行我的项目,所以我试图编译为POM,稍后再自动部署到我的Web服务器上。

解决此问题的任何提示?

谢谢

回答

2

你的项目是父(聚合),它包含子模块(多个不同的项目)。

父母必须有类型的pom。如果你想添加一场战争,它必须是一个子模块。

在你的父母,你会碰到这样的:

<modules> 
    <module>example-ear</module> 
    <module>example-war</module> 
    </modules> 

那么你的战项目将是这样的:

<?xml version="1.0"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 

    <parent> 
    <groupId>com.greg</groupId> 
    <artifactId>ear-example</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    </parent> 

    <artifactId>example-war</artifactId> 
    <packaging>war</packaging> 

    <name>com.greg</name> 
    <url>http://maven.apache.org</url> 
    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <dependencies> 
     ... 
     ... 
     ... 
    </dependencies> 
    <build> 
     ... 
     add all your war plugins here 
     ... 
    </build> 
</project> 

https://maven.apache.org/guides/mini/guide-multiple-modules.html

+1

非常感谢你。我设法将它打造成一场战争,其中包含所有期望的依赖关系。 现在有麻烦了,现在运行war文件,但我会试着在寻求帮助之前进行一些搜索 –