Creating WAR file from spring boot project Print

  • spring, springboot, spring boot, springboot framework, spring framework, war file
  • 0

Create a WAR File from Your Spring Boot Project

 

You now need to create a WAR file from your Spring Boot application. Add the following just after the <description> node in your pom.xml.

 

<packaging>war</packaging>

 

Remove the embedded Tomcat server by adding the following to your dependencies list:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-tomcat</artifactId>
   <scope>provided</scope>
</dependency>

 

Finally, enable your application as a servlet by extending your main class with SpringBootServletInitializer:

import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
    ...
}

 

Now, clean and package your application with the following command:

./mvnw clean package

You should see a message like the following:

[INFO] Building war: /home/karl/tst/demo/target/demo-0.0.1-SNAPSHOT.war

 

Take note where your new .war lives. Upload the .war file to  tomcat/webapps directory and restart tomcat. 


Was this answer helpful?

« Back