Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot WAR size with different embedded servers

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>
like image 842
Rafael Avatar asked Jan 08 '23 17:01

Rafael


1 Answers

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.

like image 176
Andy Wilkinson Avatar answered Jan 11 '23 19:01

Andy Wilkinson