How to create a WAR file in Spring Boot

Gnanendra Prasad P
1 min readJun 25, 2023

--

WAR file from Spring Boot

1. Extending Main Class

First, we need to extend our main class to SpringBootServletInitializer. This tells Spring that your main class will be the entry point to initialize your project in the server.

2. Overriding configure method

Next, we overload the configure method of SpringBootServletInitializer. We tell Spring to build the sources from our Main class. Your final Main class should look like this:

3. Configure Packaging to WAR

Finally, we tell Maven to package the project into WAR. In your pom.xml, change the attribute value for packaging from jar to war

<packaging>war</packaging>

Then try to build your project using

mvn package

You can now package your application with a jar or war file. Just change the packaging to either jar or war. And also you can still run your main method in your IDE to develop the application.

If you like what you just read, Please hit the ‘clap’ button below so that others might stumble upon this blog. For more blogs like this, please scroll down and Follow Gnanendra Prasad P or follow him here

Subscribe to my newsletter here

--

--

Gnanendra Prasad P

Spring Boot Developer | Tech Enthusiast | Mendix Rapid Certified | Kony