Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java EE Containers vs Web Containers

I'm relatively new to Java EE/EJB, and I've been reading a lot regarding Java EE containers. I've had experience working with a web container (WAR file in JBoss). I am also aware that JBoss can also be used as a Java EE container.

What is the difference between a Java EE container against a web container?

I know Java EE is also able to contain a .war file. Are they different and what are their differences? Are there any preferences vendor specific-wise which is better?

like image 290
mel3kings Avatar asked Jun 19 '13 00:06

mel3kings


People also ask

Which Java EE technologies can be used in web and EJB containers?

A Java EE server provides EJB and web containers. Enterprise JavaBeans (EJB) container: Manages the execution of enterprise beans for Java EE applications. Enterprise beans and their container run on the Java EE server.

What is the difference between web container and servlet container?

Web containers are a part of a web server and they generally processes the user request and send a static response. Servlet containers are the one where JSP created components reside. They are basically responsible to provide dynamic content as per the user request.

Is Tomcat a Java EE container?

Apache Tomcat is a long-lived, open source Java servlet container that implements core Java enterprise (now Jakarta EE) specifications, including the Jakarta Servlet, Jakarta Server Pages, and Jakarta WebSocket specs.


1 Answers

First of all, "J2EE" is an obsolete abbreviation, it is now simply called "Java Enterprise Edition" or Java EE.

Contrary to the servlet container (e.g. Tomcat), "full" Java EE application servers contain also an EJB container. EJB are Enterprise Java Beans and you can read a lot about them for example here (chapter IV). EJBs are now in version 3.2 (Java EE 7 and Java EE 8), previous versions are 3.1 (Java EE 6) and 3.0 (Java EE 5); however the greatest difference is between v2 and v3.

EJBs are designed to keep a business logic of your application. For example, stateless session bean can calculate something, or represent a Web service or whatever your application needs to do. Message-driven beans can listen on message queues, therefore they are useful if you want asynchronous communication. Singleton beans guarantee one instance per bean etc.

Regarding the file type, EJB is packed into a .jar file, Web application into a .war file, and if you want to mix them in a single application, that would be the .ear file ("enterprise archive").

Beside EJBs, "full" application server also takes care about transactions, security, JDBC resources... I would highly recommend using it over a servlet container, but the benefits come with the complexity so you will have to spend a reasonable amount of time to learn how to deal with e.g. Websphere (Payara and WildFly are much simpler, and are my favourite). JBoss and Weblogic are also quite popular, and if you are familiar with Tomcat take a look at TomEE.

like image 131
Miljen Mikic Avatar answered Sep 22 '22 17:09

Miljen Mikic