Java EE Containers vs Web Containers

36,964

Solution 1

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.

Solution 2

Java EE container: Manages the execution of EJB, JMS, JTA run on the Java EE server e.g. JBoss, Glassfish.

Web container: Manages the execution of web pages, servlets, and some EJB components for Java EE applications. Web components and their container run on the Web server such as Jetty, tomcat.

Solution 3

The web-container and EJB-container are subsets of Java EE containers. Java EE containers also encompass the application client container and applet container.

Here's what the doc says:

The deployment process installs Java EE application components in the Java EE containers.

  • Java EE server: The runtime portion of a Java EE product. A Java EE server provides EJB [container and web container]*.

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

  • Web container: Manages the execution of JSP page and servlet components for Java EE applications. Web components and their
    container run on the Java EE server.

  • Application client container: Manages the execution of application client components. Application clients and their container run on the client.

  • Applet container: Manages the execution of applets. Consists of a web browser and Java Plug-in running on the client together.

*In the doc they use the plurial form, but actually you only have one web container and one EJB container per Java EE server.

Share:
36,964
mel3kings
Author by

mel3kings

Melchor Tatlonghari: http://www.linkedin.com/pub/melchor-tatlonghari/6a/198/b11 https://github.com/mel3kings https://www.credly.com/users/melchor-tatlonghari/badges https://www.sysdotoutdotprint.com/ https://medium.com/free-code-camp/how-a-stackoverflow-account-can-secure-you-a-seat-at-the-recognised-developer-table-cc782e1c84de https://medium.com/@mckinseydigital/3-mistakes-i-made-learning-the-software-engineering-skillset-and-how-to-avoid-them-8e194ff09b01

Updated on July 09, 2022

Comments

  • mel3kings
    mel3kings almost 2 years

    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?

  • mel3kings
    mel3kings about 11 years
    +1 for the complete answer, I'm looking for a comparison of the application servers you have mentioned. with regards to complexity/ease of integration etc.
  • Miljen Mikic
    Miljen Mikic about 11 years
    @melt321 Glad to help. Regarding the comparison, I have worked only with Websphere and Glassfish, so I'll recommend other articles: hwellmann.blogspot.com/2011/06/java-ee-6-server-comparison.h‌​tml, stackoverflow.com/questions/217827/…, stackoverflow.com/questions/1224822/websphere-vs-weblogic
  • user584910
    user584910 over 4 years
    EJB can be executed on web container as well as on EJB container, how are both different, when to use which container. Can you explain pros/cons of Web and EJB containers in regard to EJB.?
  • Petronella
    Petronella about 2 years
    This is a mix of info and incomplete answer that can confuse someone trying to understand the JEE containers concepts