Today, it is easy to develop Spring Boot applications using tools such as annotations and to initialize them as Maven, Spring Boot, and embedded servers.

So, as we do on a daily basis, when we build a Spring Boot application, by default we package the application into a JAR file and execute the main application classes into a main embedded Tomcat server. You can then run your application tests in your environment.

What if we want to make the application server separate and place the application on an existing server (such as WebLogic, JBoss, Wildfly, etc.)?

To do this, we must make our application a WAR file.

Here are some simple steps to do this:

1. Update Maven pom.xml with the following changes

Set the packaging label to WAR


Set all Tomcat JAR files to PROVIDE


Then, you need to update the maven-war-plugin so that it doesn’t fail if web.xml is lost. You can do this by updating the plug-in information in the build tag and by removing the plug-in in the org.springframework.boot POM, as shown below:

<plugins> <! -- <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> --> < plugin > < groupId > org. Apache. Maven. Plugins < / groupId > < artifactId > maven - war - the plugin < / artifactId > < version > 3.1.0 < / version > <executions> <execution> <id>default-war</id> <phase>prepare-package</phase> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </execution> </executions> </plugin> </plugins>

2. Update the Main class to extend the SpringBootServletInitializer

@SpringBootApplication public class SpringBootWarDeploymentApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(SpringBootWarDeploymentApplication.class); } public static void main(String[] args) {, args); }}

3. Rename the file SpringBootWarDeployment-0.0.1.war to the required name SpringRestApi.war.

4. Check whether the server lacks web.xml file functionality

Typically, because some containers cannot deploy the dash version, the version number is removed from the build file. This can be said to be a small technique, I hope you can be useful oh.