Spring boot app vs .war file deployed on Tomcat/Jetty

17,347

Solution 1

Package it to .war file and deploy it on Tomcat/Jetty?

Don't do this if at all possible. Reason: with embedded tomcat (or any other server runtime like undertow, netty, jetty etc) it's much easier to build a micro-services architecture.

As Josh Long once said in one of his Spring IO talks “make Jar, not War”

On the other hand, if you have an existing infrastructure out there with servlet containers and already there are multiple application.wars running in those servlet containers, and all you have to do is just package your application as a war file and hand it over to a release team (or rather you are forced to just reuse the existing infrastructure), then it's a different story...But, tech-world is already moving away from this practice.

Again, in the spirit of microservices, in the spirit of what spring boot intended for, I would encourage you to use embedded server and make runnable jar file rather than going with traditional deployment.

Edit

If you are dockerizing your application, you have 2 options to package your tomcat in your "final artifact" (by "final artifact", I meant docker image, not the jar. Jar is just an intermediate artifact here).

  1. Use embedded tomcat so that tomcat will be packed in your jar and use a JVM docker image

OR

  1. Exclude tomcat from your jar and just pack your application and use a tomcat Docker image.

Still, any day, I would go with 1st option because that make development process much easier (and this goes with out saying, on-boarding a new developer will be easier).

Solution 2

As described on the product page those jars include the servlet container and will directly start it.

Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)

If you plan to run your application on one host with nothing else next to it (docker?) this might be a nice possibility - if your host contains other apps the approach to deploy wars would be more interesting as you can have those servlet containers only once on your host.

Share:
17,347
countryroadscat
Author by

countryroadscat

Updated on July 10, 2022

Comments

  • countryroadscat
    countryroadscat almost 2 years

    In my case let's consider a simple RESTful service created and configured with Spring Boot. This service communicates with a database (e.g. Postgres).

    What is a difference between:

    • Building a Spring Boot .jar file and run it on my remote public host via java -jar myservice.jar?

    or

    • Package it to .war file and deploy it on Tomcat/Jetty?

    First option seems to be a lot easier, u just need to run a .jar. In second option u need to create Tomcat instance, run it and then deploy a .war file. Is there any other difference? Any pros and cons of both method?