Reputation: 6612
I have a spring boot application with a double build, local (fat jar) and war (war).
I handled it this way:
<packaging>${application.packaging}</packaging>
...
<profiles>
<profile>
<id>dev</id>
<properties>
<application.packaging>jar</application.packaging>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>war</id>
<properties>
<application.packaging>war</application.packaging>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>false</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Strangely enough, even though the default profile is dev so the packaging is jar, the eclipse error still pops up. It doesn't seem to have any effect on my build but I still want to get rid of it. How can I do that?
Upvotes: 1
Views: 807
Reputation: 124516
Remove the plugins from your profiles. Only change the packaging.
<packaging>${application.packaging}</packaging>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<properties>
<application.packaging>jar</application.packaging>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>war</id>
<properties>
<application.packaging>war</application.packaging>
</properties>
</profile>
</profiles>
This is all you need. Nothing more and nothing less. The war plugin used by Spring Boot is already a newer one which doesn't require a web.xml
anymore.
Although I would strongly recommend against it and use war
as packaging for dev as well. You can perfectly well execute the war
like you can the jar
. So just build a war
.
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</provided>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
This will build a war file that is both executable as well as deployable. This is all explained in the Spring Boot Documentation as well. It has a whole section on how to that.
Upvotes: 1