Converting a Spring Boot JAR Application into WAR

[Social9_Share type="horizontal"]

Converting a Spring Boot JAR application into WAR

This is the Part-III series of spring boot. To get a basic understanding about spring boot, you can go to Part I. To learn how to build a restful service using Spring Boot, you can read Part II .

In this post, lets discuss how to convert the existing spring boot application into a war file. Let’s get started.Let’s modify the existing application.
Open pom.xml and modify as given below. Change the packaging from jar to war.


Next, let’s create a web entry point for the application. Create a class that extends SpringBootServletInitializer.

This class makes use of SpringFramework’s Servlet 3.0 support and configures the application when launched by the container. You need to override the configure method.

The next step is to select pom.xml right click -> Run As -> Maven install. The application is packaged as a war file.


Then, select your project right click -> Maven -> Update Project. Now your build is updated and ready to run.


The last step is, to deploy your application in the server. select your project and right click Run As -> Run on Server. This application runs on Tomcat Server 8.0.


Once, the server is started, you can go to the browser and open your application. You cannot open the application from the internal browser of eclipse.

The url of the application is http://localhost:8080/<context-root>/path. To get the context root select your project right click -> Properties. A new window opens.Select Web Project Settings. you can get the Context root


In our case, the URL is http://localhost:8080/SpringBootDemo/home


You can also try the other url as http://localhost:8080/SpringBootDemo/home/Ram


And this http://localhost:8080/SpringBootDemo/bookDetails


That’s it. We have converted a spring boot application jar file into a war file and also deployed it.
You can download the complete project as a zip file from the github. SpringBootDemo

Happy Learning

Post a comment