我有一个 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 模块都正确编译到它的目标,我的项目正在运行。 但是,因为我打算在 Web 服务器上运行我的项目,所以我试图编译成 POM,稍后自动部署到我的 Web 服务器。
有什么解决问题的技巧吗?
谢谢,
最佳答案
您的项目是父项目(聚合器),它包含子模块(许多不同的项目)。
parent 必须有 pom 类型。如果你想添加一场 war ,它必须是一个子模块。
在你的 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
关于java - Maven war - 值为 'packaging' 的 'war' 无效。聚合器项目需要 'pom' 作为包装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45351672/