Maven war - 'packaging' 的值 'war' 无效。聚合器项目需要 'pom' 作为包装

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

我有一个以前使用以下结构的 Maven 项目,除了 war 打包、构建插件和 webapp/:

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>

但是,每当我尝试将我的项目编译为 war 时,我都会收到以下错误

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

之前,我编译为 pom,没有 maven war 插件,每个 maven 模块都正确编译到它的目标,我的项目是 运行ning。 但是,因为我打算 运行 我的项目在网络服务器上,我试图编译成一个 POM,稍后自动部署到我的网络服务器。

有什么解决问题的技巧吗?

谢谢,

您的项目是一个 parent(聚合器),它包含 child 个模块(许多不同的项目)。

A parent 必须有 pom 类型。如果你想添加一个 war 它必须是一个 child 模块。

在您的 parent 中,您将有类似的内容:

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

那么您的 war 项目将如下所示:

<?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>