没有父pom.xml的spring-boot无法生成war包装

Mat*_*ner 29 java war maven parent-pom spring-boot

我使用了spring-io提供的gs-convert-jar-to-war示例.它描述了如何在spring引导项目中生成war包装.

spring-boot文档允许使用自己的父pom,因此省略了所有spring-boot项目的预定义父pom.必须添加以下依赖项:

<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.0.1.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)

我将此更改(仅此更改)应用于示例.之后,再也不可能产生战争了.我收到以下错误消息:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project gs-convert-jar-to-war: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

以下是修改后的pom.xml的完整列表:

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

    <groupId>org.springframework-sample</groupId>
    <artifactId>gs-convert-jar-to-war</artifactId>
    <version>0.1.0</version>
    <packaging>war</packaging>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <!-- Import dependency management from Spring Boot -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>1.0.1.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
            </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
            </dependency>
    </dependencies>

    <properties>
        <start-class>hello.Application</start-class>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>http://repo.spring.io/libs-milestone</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>http://repo.spring.io/libs-milestone</url>
        </pluginRepository>
    </pluginRepositories>

</project>
Run Code Online (Sandbox Code Playgroud)

有没有想法克服这个问题?

在我的项目中,我将使用我自己的父pom,因为它定义了很多关于公司的东西.

Dav*_*yer 66

您删除了父级,因此您丢失了WAR插件配置的声明.这里是:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

请参阅此处获取源代码.

注意这不是必需的Spring Boot 2.0父pom及以上(war插件版本不同),或者如果你使用最新的war插件.