Spring Boot Create War for Tomcat – Example

If you want to see how to config pom.xml to build as a war file that can be deployed in Tomcat or other Servlet containers, this page is for you.

This example is a part of  Spring Boot with all examples

Full Code with Spring Boot 1.5.8.RELEASE:

12_spring-boot-war-for-tomcat.zip

What you need for run this:

  • Maven 3
  • Java 8
  • Tomcat 7.x or later

What the code will do:

  • Show how to config Spring Boot and build as war that can be deployed in Tomcat or other Servlet containers

Explain:

This is the file structure:

Most of code here are the same as Spring Boot with JSP – Example . Almost everything are the same, only the yellow in this pom.xml that is different:

You just need this:

The key here is that you just have to tell that Tomcat is <scope>provided</scope>.

Try:

run this in console:

Then copy target/spring-boot-12-1.0-SNAPSHOT.war to tomcat/webapps. Rename to file to ROOT.war. Or you can use your IDE starting this up as Tomcat (I will not explain here).

Then start Tomcat. You should see something like this:

Open a browser and try to go to this url:

Then you should see this: