Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded vs Non-Embedded Java Server

Tags:

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?

like image 930
Jackson Avatar asked Apr 19 '14 23:04

Jackson


People also ask

What is embedded server in Java?

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

What is the advantage of having an embedded Tomcat server?

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.

What is the use of embedded server?

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.

What is the use of embedded server in spring boot?

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).


2 Answers

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

like image 79
dimoniy Avatar answered Sep 20 '22 17:09

dimoniy


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

like image 20
Cameron McKenzie Avatar answered Sep 20 '22 17:09

Cameron McKenzie