Spring Boot - Running main class from IDE with Spring Boot War packaging and with spring-boot-starter-tomcat scope=provided

When we package Spring Boot Web application as war (check out the related tutorial here) so that it can be deployed to a Servlet container, we need to exclude spring-boot-starter-tomcat dependency to avoid interfering of the Boot's embedded tomcat and the runtime Servlet container. By doing so we can no longer run the boot application from IDE or run it via boot plugin or as executable war file, that's because all of these methods need Spring Boot's embedded tomcat server. Instead of adding/removing spring-boot-starter-tomcat to work in all environments, we can use maven profiles as follows:


<project .....>






Now we can run the web application from IDE, via spring-boot:run or via executable war file as usual.

To deploy to a Servlet container or run via tomcat maven plugin (included in pom.xml), we need to specify the profile 'warBuild':

mvn -P warBuild tomcat7:run-war

Example Project

Dependencies and Technologies Used:

  • Spring Boot 1.5.9.RELEASE
    Corresponding Spring Version 4.3.13.RELEASE
  • spring-boot-starter-web : Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container.
  • spring-boot-starter-tomcat : Starter for using Tomcat as the embedded servlet container. Default servlet container starter used by spring-boot-starter-web.
  • JDK 1.8
  • Maven 3.3.9

traditional-war-packing-running-main-method Select All Download
  • traditional-war-packing-running-main-method
    • src
      • main
        • java
          • com
            • logicbig
              • example
    • pom.xml

    See Also