4

I am doing som experimentation with spring-boot and i realized that when i use embedded Tomcat server the resulting WAR size is smaller than when i use Jetty or even Undertow servers with same rest dependencies.

How is this possible? ... it is supposed that Undertow and Jetty should be ultralight compared with tomcat.

Sizes are:

Tomcat ~18Mb

Undertow ~21Mb

Jetty ~24Mb

Any of them looks too big for me since this is dummy REST endpoint. These are my dependencies:

    <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-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- <dependency> -->
        <!-- <groupId>org.springframework.boot</groupId> -->
        <!-- <artifactId>spring-boot-starter-tomcat</artifactId> -->
        <!-- </dependency> -->
        <!-- <dependency> -->
        <!-- <groupId>org.springframework.boot</groupId> -->
        <!-- <artifactId>spring-boot-starter-undertow</artifactId> -->
        <!-- </dependency> -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
<!--        <dependency> -->
<!--            <groupId>org.springframework.boot</groupId> -->
<!--            <artifactId>spring-boot-starter-test</artifactId> -->
<!--            <scope>test</scope> -->
<!--        </dependency> -->
    </dependencies>
Rafael
  • 2,521
  • 2
  • 33
  • 59
  • 1
    Did you try unzipping the .war file and looking into the /lib folder to see where the extra weight comes from? – kryger Mar 17 '15 at 22:22

1 Answers1

9

Spring Boot includes three sample applications, spring-boot-sample-jetty, spring-boot-sample-tomcat, and spring-boot-sample-undertow, with minimal, and pretty much identical, functionality. With Spring Boot 1.2.2.RELEASE, the archives sizes are:

  • spring-boot-sample-jetty - 12MB
  • spring-boot-sample-tomcat - 9.8MB
  • spring-boot-sample-undertow - 9.6MB

As you can see Tomcat and Undertow are pretty much the same and the Jetty artifact is ~20% larger.

One notable reason for the size difference is JSP support. Undertow doesn't support JSPs and Spring Boot doesn't include Tomcat's JSP support by default. ~1.7MB of the Jetty-based archive is taken up by the Eclipse Java compiler that's used for JSP compilation. If you want to use Jetty and aren't using JSPs, you could exclude the org.eclipse.jetty:jetty-jsp dependency. This reduces the Jetty-based artifact's size to 8.8MB.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • Also how does this increase the app size when these embedded app-servers are deployed? – Zon Jul 31 '19 at 11:37