18.1 Weighing deployment options
You can build and run Spring Boot applications in several ways, including the following:
- Running the application directly in the IDE with either Spring Tool Suite or IntelliJ IDEA
- Running the application from the command line using the Maven
springboot:rungoal or GradlebootRuntask - Using Maven or Gradle to produce an executable JAR file that can be run at the command line or be deployed in the cloud
- Using Maven or Gradle to produce a WAR file that can be deployed to a traditional Java application server
- Using Maven or Gradle to produce a container image that can be deployed anywhere that containers are supported, including Kubernetes environments.
Any of these choices is suitable for running the application while you’re still developing it. But what about when you’re ready to deploy the application into a production or other nondevelop?
Although running an application from the IDE or via Maven or Gradle isn’t considered a production-ready option, executable JAR files and traditional Java WAR files are certainly valid options for deploying applications to a production environment. Given the options of deploying a WAR file, a JAR file, or a container image, how do you choose? In general, the choice comes down to whether you plan to deploy your application to a traditional Java application server or a cloud platform, as described here:
- Deploying to a Platform as a Service (PaaS) cloud — If you’re planning to deploy your application to a PaaS cloud platform such as Cloud Foundry https://www.cloudfoundry.org/, then an executable JAR file is a fine choice. Even if the cloud platform supports WAR deployment, the JAR file format is much simpler than the WAR format, which is designed for application server deployment.
- Deploying to Java application servers — If you must deploy your application to Tomcat, WebSphere, WebLogic, or any other traditional Java application server, you really have no choice but to build your application as a WAR file.
- Deploying to Kubernetes — Modern cloud platforms are increasingly based on Kubernetes https://kubernetes.io/. When deploying to Kubernetes, which is itself a container-orchestration system, the obvious choice is to build your application into a container image.
In this chapter, we’ll focus on the following three deployment scenarios:
- Building a Spring Boot application as an executable JAR file, which can possibly be pushed to a PaaS platform
- Deploying a Spring Boot application as a WAR file to a Java application server such as Tomcat
- Packaging a Spring Boot application as a Docker container image for deployment to any platform that supports Docker deployments
To get started, let’s take a look at what is perhaps the most common way of building a Spring Boot application: as an executable JAR file.
