Maven 战争 - 具有价值'war'的'packaging'无效。聚合器项目需要'pom'作为打包



我有一个maven项目,它以前使用以下结构,除了战争打包,构建插件和webapp/:

项目结构 和以下父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 服务器。

有什么解决问题的提示吗?

谢谢

您的项目是父项目(聚合器(,它包含子模块(许多不同的项目(。

父母必须有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

就我而言,我的pom错过了以下<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>