spring boot war without tomcat embedded

I want to create a war file without embedded tomcat with maven. Here the relevant part of my pom

...
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.1.6.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <!-- Add tomcat only if I want to run directly -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
...

How ever if I run mvn package I get a war, where the tomcat*.jar are in a provided-lib folder but still in the lib-folder. I read build-tool-plugins-maven-packaging, but can't find what's wrong.

I know a main idea is to run it as an application, how ever our customer want's to deploy it on his application-server.

Following the Hint from M. Deinum I excluded the tomcat-depedency.

With the following pom.xml (relevant snippet) a maven clean package has the result I want to get.

...
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.1.6.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <!-- Add tomcat only if I want to run directly -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
...

Warning for idea-user: You must activate "Include dependencies with the provided scope" in the run-configuration (see Unable to start spring-boot application in IntelliJ Idea for more information)

Deploying Spring Boot app as WAR, your JAR Spring Boot app to be packaged and deployed as WAR without are packaged as executable JAR files with embedded Tomcat. Spring Boot includes an embedded Tomcat server which makes it easy to run web applications. The application code, libraries, and embedded Tomcat server are packaged in an executable JAR that can be run from the command-line without any additional server setup. However, the embedded Tomcat server is not suitable for every environment.

I'm not sure if that's the spring-boot way of doing it, but you can exclude the tomcat jars using the maven-war-plugin configuration. That is, add the following to your pom.xml:

<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
            </configuration>
        </plugin>
    </plugins>
</build>

Using this approach, the war generated is not executable (cannot be run on command line using java -jar ) but can only be deployed to any servlet container

Spring Boot With External Tomcat, war file. In a Tomcat environment, you wouldn't like to use the embedded server. The Tomcat server won't hit your main method. Hence� How load a external “war” file to the embedded tomcat server of spring boot 30 Spring Boot application gives 404 when deployed to Tomcat but works with embedded server

I had this same need but removing the mentioned dependency didn't worked. I was able to get the WAR file by adding this <packaging>war</packaging> dependency to my pom file.

I used this Spring article as a guide... sharing so this may help other people as well.

Deploy a Spring Boot WAR into a Tomcat Server, By default, Spring Boot builds a standalone Java application that can run as a desktop application or be configured as a system service, but there� In this article, we will show you how to create a Spring Boot traditional WAR file and deploy to a Tomcat servlet container. In Spring Boot, to create a WAR for deployment, we need 3 steps: Extends SpringBootServletInitializer; Marked the embedded servlet container as provided. Update packaging to war Tested with. Spring Boot 2.1.2.RELEASE

Changing spring-boot-starter dependency from

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

To this one will exclude the embedded tomcat server.

   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Deploying Spring Boot Applications, There are lots of configuration options for the embedded Tomcat. move from a jar build to a war build in Maven: comment out the declaration of the No story about deployments would be complete without touching on the� Spring Boot's embedded tomcat is very handy, for both development and deploy. But what if an another (3rd-party) WAR file (for example, GeoServer) should be added? Perhaps the following is the normal procedure: Install a normal Tomcat server. Build the Spring Boot application as a WAR file, and add it to the webapps folder of the Tomcat.

I think that the easiest way to build a final WAR from your existing Spring Boot project without embedded Tomcat is the following:

1) Set WARpackaging for your artifact: <packaging>war</packaging>

2) Set the Tomcat Server dependency to provide:

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

If some of your existing Spring Boot dependencies contain it by default, just exclude it. Example:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
</dependency>

That is it.

Getting Started, A popular subject is that many people still wish to generate WAR files to be deployed a WAR file and declare the embedded container dependencies as " provided". for OpenJDK™, Spring, and Apache Tomcat� in one simple subscription. In order to run a spring boot application on tomcat generally the produced artifact has to be a war application. In order to make it run on tomcat inside Eclipse you have to use a WTP-Project (Web Tools Platform aka Dynamic Web Module) using the eclipse-wtp gradle plugin.

Spring Boot - Deploy WAR file to Tomcat, Marked the embedded servlet container as provided. Update packaging to war. Tested with. Spring Boot 2.1.2.RELEASE; Tomcat 8 and 9; Maven� Choose spring-boot-tutorial-basics as Artifact; Choose following dependencies Web; DevTools; Click Generate Project. Import the project into Eclipse. File -> Import -> Existing Maven Project. Default Embedded Server with Spring Boot - Tomcat. We have included Spring Boot Starter Web in our dependencies when creating the spring boot project.

spring boot war without tomcat embedded - spring - html, I want to create a war file without embedded tomcat with maven. Here the relevant part of my pom <parent> <groupId>org.springframework.boot</ groupId>� spring-boot-starter-tomcat: enable an embedded Apache Tomcat 7 instance, by default. We have overriden this by defining our version. This can be also marked as provided if you wish to deploy the war to any other standalone tomcat. tomcat-embed-jasper: provides support for .jsp file rendering.

How to Deploy a Spring Boot WAR to Tomcat, The application code, libraries, and embedded Tomcat server are packaged in an executable JAR that can be run from the command-line without�

Comments
  • The fact that the jars are still there doesn't mean you cannot deploy it as a war. You can perfectly deploy it as is. Make sure that you exclude tomcat from the spring-boot-starter-web dependency.
  • @niels, you edited this question, and since revision 2 it includes the answer to your question. What about reverting to your initial answer and providing a separate answer?
  • @Abdull good idea. It makes it more clear.
  • But if the spring-boot-starter-tomcat is commented out, how do you run the app? I tried it this way, and deployed it to a tomcat container, but got error messages then. All similar to: org.apache.catalina.startup.ContextConfig checkHandlesTypes WARNING: Unable to load class [org.apache.tomcat.util.descriptor.web.NameRule] to check against the @HandlesTypes annotation of one or more ServletContentInitializers. java.lang.ClassNotFoundException: org.apache.tomcat.util.descriptor.web.NameRule etc.
  • You can deploy the war in an arbitrary servlet-container. If your application doesn't need tomcat classes it works fine this way. Is it possible that you need at compile-time the tomcat-classes? How do you compile? mvn from commandline? Make sure you make a mvn clean at the beginning.
  • I use gradle, I already figured it out though. The build process (bootRepackage) produces two artifacts, one with and one without the embedded Tomcat container. Turned out I took the wrong artifact for the external Tomcat deployment - should take the war without the embedded Tomcat then.
  • SUPERB! Thank you very much.
  • When i run my application with above suggestion, it gives me error "Unregistering JMX-exposed beans on shutdown"