[ACCEPTED]-One Spring Boot project, deploy to both JAR or WAR-spring-boot
I managed to do it by adding
<packaging>${packaging.type}</packaging>
to the POM file 5 and then setting different profiles for 4 JAR and WAR:
<profiles>
<profile>
<id>jar</id>
<properties>
<packaging.type>jar</packaging.type>
</properties>
</profile>
<profile>
<id>war</id>
<properties>
<packaging.type>war</packaging.type>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
</profiles>
Now mvn package -P war
produces a WAR and mvn package -P jar
produces 3 a JAR.
Another option is to create separate 2 modules for JAR and WAR, but I didn't go 1 that route.
What's wrong with a WAR file that's executable? Isn't 1 that what you really need?
P.S. like
java -jar name.war
We've recently had a similar requirement, where 23 an existing Spring Boot based project that 22 was originally packaged as an executable 21 Jar needed to support Tomcat and WildFly 20 deployments.
Due to some dependencies used 19 in this project (for example WebJars), a 18 simple switch to WAR package wasn't an option 17 since some of those dependencies were required 16 for WildFly (VFS support) but not for other 15 deployment.
The solution was to restructure 14 the project modules in a way that core module 13 contained the actual project but without 12 having Spring Boot’s plugin applied, while 11 several package modules would depend on core module 10 and configure deployment artifact specifics 9 (Boot and other plugins, deployment specific 8 dependencies etc.).
That way project build 7 was able to generate multiple deployment 6 artifacts (Boot's executable JAR, traditional 5 WAR and WildFly specific WAR) in a single 4 build run.
In case anyone finds this useful, the 3 sample project to demonstrate the approach 2 is available on Github. The project can be built by either 1 Gradle or Maven.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.