49
votes

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?

6

6 Answers

88
votes

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.

27
votes

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.

4
votes

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.

0
votes

I think maybe the difference between them are the protocols which they support.

For example,we don't try to manage the transaction in a web container,like Tomcat, we usually try to control in the web-project which is deployed in Tomcat. While a web/application server like EJB takes the opposite.

-1
votes

A Java EE Container is an application server solution that supports a web container, EJB 3, and other Java EE APIs and services.

Oracle WebLogic server, GlassFish server, IBM WebSphere application server, JBoss Application server and Caucho Resin are examples of Java EE containers...

-2
votes

Applications can be categorised as follows:

  • Desktop Application like GUI,
  • Web Application like dynamic web pages,
  • Enterprise Application which deals with core business processing.

Enterprise Application: Generally not much of user interaction. In this case, if you want your application to interact with disparate applications distributed across intranet/Internet using web services, JMS or JTA (connecting with a mainframe transaction server) then you need Java EE with EJB containers and other security features.

Web Container: Rather, if you want to interact with distributed application using JNI or just talk to RDBMS, or just render static or dynamic web pages then the web container is enough for you. Your HTTP request from the browser can invoke and execute Java programs through a servlet. The Java program can invoke a JDBC API to talk to the RDBMS. Similarly, you can invoke a C or Java program from another server using JNI or RMI.