I'm working on a Java project and have been using a Tomcat server for local testing. However I am about to push up to Heroku and I found an article that suggests to use "embedded" Tomcat.
I looked around to see what exactly "embedded" meant in the context of a Java server but it seems like everyone on Google already understands what "embedded" means. I don't. What is the difference between deploying a "regular" Tomcat server and an "embedded" one?
"Embedded" means that you program ships with the server within it as opposed to a web application being deployed to external server. With embedded server your application is packaged with the server of choice and responsible for server start-up and management.
Embedded Tomcat offers a way to package Java web applications that is consistent with a microservices-based approach to software development. It also makes it easier to distribute Java web applications through Docker containers and manage them through a container orchestration service, such as Kubernetes or OpenShift.
Embedded Servers Have High Utility As a concept, embedded servers might take some time to get used to. These can be used with applications for deployment in high-workload environments, without sacrificing any reliability or stability. Embedded servers are also quite lightweight.
For example, for a Spring Boot Application, you can generate an application jar which contains Embedded Tomcat. You can run a web application as a normal Java application! Embedded server implies that our deployable unit contains the binaries for the server (example, tomcat. jar).
"Embedded" means that you program ships with the server within it as opposed to a web application being deployed to external server.
With embedded server your application is packaged with the server of choice and responsible for server start-up and management.
From the user standpoint the difference is:
war
archive which needs to be deployed to some serverEmbedding a server is very useful for testing purposes where you can start or stop server at will during the test.
Traditionally, to host Java web applications, you installed a single Tomcat instance on your server, and pushed all of your WAR files onto that one server. Maybe you clustered a few Tomcat instances together, but the idea is the same. There was one Tomcat server, and all of your Java web apps were deployed to it.
Traditional vs Embedded Tomcat
In the world of microservices, things are a little different. Instead of one Tomcat server hosting many web applications, with microservices, we take the one web application, deploy that one web application to a one tomcat server, and then zip it all up in a zip, jar or war file that is executable through the Java command. So now we have a single executable file that contains everything you need to run the web app, including the Tomcat server.
Container Based Distribution
Some products ship their entire product in an embedded servlet engine. You can get Jenkins in a single executable WAR file, although I believe they embed Jetty, not Tomcat, but it's the same idea. But less likely than distributing the jar/war, what people do is package the whole thing up in a docker container and deploy it all to Kubernetes or Heruku or whatever.
So that's kinda the idea behind an embedded tomcat server.
Maven and Embedded Tomcat
One of the easiest way to create an embedded tomcat server is with Apache Maven. Here's an example of a Maven build that not only builds a web app, but also downloads tomcat and packages the whole thing in an executable JAR:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With