Question

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?

Was it helpful?

Solution

"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:

  • Application with embedded server looks like a regular java program. You just launch it and that's it.
  • Regular web application is usually a war archive which needs to be deployed to some server

Embedding a server is very useful for testing purposes where you can start or stop server at will during the test.

OTHER TIPS

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:

Embedded Tomcat with Maven

From here, it's when you "embed" tomcat into your application. That is, you are responsible for starting and stopping tomcat. This is the reverse of a normal container operation, but you might find it useful for rapid deployment and testing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top