14

How can we exclude embedded Tomcat server from Spring Boot application so that we can run that jar on JBoss Server?

Alex Chermenin
  • 838
  • 12
  • 24
Deepesh Rathore
  • 281
  • 2
  • 4
  • 13
  • 2
    You don't need to exclude it it will just run on the server AND be executable. – M. Deinum Dec 15 '17 at 07:23
  • 1
    Okay, that means even if we run jar on production server, in our case we are using Jboss on prod,will automatically deploy on jboss instead of Tomcat? – Deepesh Rathore Dec 15 '17 at 07:26
  • 1
    I was assuming a `war` file and not a `jar` file. You should at least make the dependencies scoped `provided` so that they are moved to a different directory. That directory is used by Spring Boot but not when deploying the file. – M. Deinum Dec 15 '17 at 07:27
  • Incase of jar file what it gonna do, will it deploy on embedded Tomcat or ll it deploy on jboss. – Deepesh Rathore Dec 15 '17 at 07:28

6 Answers6

18

You can exclude in pom file:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>tomcat-embed-el</artifactId>
            <groupId>org.apache.tomcat.embed</groupId>
        </exclusion>
        <exclusion>
            <artifactId>tomcat-embed-core</artifactId>
            <groupId>org.apache.tomcat.embed</groupId>
        </exclusion>
        <exclusion>
            <artifactId>tomcat-embed-websocket</artifactId>
            <groupId>org.apache.tomcat.embed</groupId>
        </exclusion>
    </exclusions>
</dependency>

You can follow this link with screenshots

Spring documentation on Embedded servlet container

campisano
  • 229
  • 2
  • 10
Yogi
  • 1,805
  • 13
  • 24
  • When i run my application with above suggestion, it gives me error "Unregistering JMX-exposed beans on shutdown" – Tatkal Apr 11 '18 at 09:27
9

you can modify your POM.xml file as follows:

  <!-- Removing the dependency for the embedded tomcat -->
            <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>
aditya gupta
  • 403
  • 2
  • 10
2

Another way is to mark the tomcat dependency's scope as provided in your pom.xml:

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

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-websocket</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-core</artifactId>
        <scope>provided</scope>
    </dependency>
jumping_monkey
  • 5,941
  • 2
  • 43
  • 58
1

Add the <exclusions> tag in dependency with <artificatId> as 'spring-boot-starter-web'

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

Your final dependency should look like:

<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>
</dependencies>
David Buck
  • 3,752
  • 35
  • 31
  • 35
1
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <excludeGroupIds>org.apache.tomcat.embed</excludeGroupIds>
    </configuration>
</plugin>

You can review this article. Dependency Exclusion

Murat Kara
  • 791
  • 4
  • 15
Sergei K
  • 51
  • 3
0

Better to mention

scope as provided in pom.xml file

to exclude embedded tomcat server in spring boot maven based application.

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