33

I used the example gs-convert-jar-to-war provided by spring-io. It describes how to generate war packaging within a spring boot project.

The spring-boot documentation allows for using own parent poms, thus omitting the predefined parent pom for all spring-boot projects. The following dependency has to be added:

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

I applied this change (and only this change) to the example. Afterwards it is no longer possible to generate the war. I get following error message:

[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]

Here is the complete listing of the modified 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>

Is there any idea to overcome the problem?

In my project I will use my own parent pom, because it defines a lot of stuff regarding the company.

Matthias Brenner
  • 372
  • 1
  • 3
  • 10

1 Answers1

74

You removed the parent, so you lost its declaration of the WAR plugin configuration. Here it is:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>

See here for the source code.

N.B. this is not necessary with Spring Boot 2.0 parent pom and above (the war plugin version is different), or if you use the latest war plugin.

Dave Syer
  • 56,583
  • 10
  • 155
  • 143
  • Thanks for the hint. I added the missing plugin, but then it complains about missing web.xml:Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode). If I provide the spring-boot based parent, it is working without an own declaration of a web.xml. – Matthias Brenner Apr 17 '14 at 07:25
  • You must have forgotten to add the failOnMissingWebXml=false (as per the answer above)? – Dave Syer Apr 17 '14 at 11:36
  • 1
    Sorry, the cause was stupid: I used packaging "war" and the maven-jar-plugin which I replaced by maven-war-plugin. Now it is working. Thank you for the tipp. – Matthias Brenner Apr 22 '14 at 10:11