EJB 3 : Remote View – Client and EJBs in the Same EAR (Tutorial 6)

How to Define a Remote View?

How to invoke a Session Bean packaged in another WAR but deployed in the Same EAR?

Will the client need a Remote or Local View?


Tutorial 1 : Eclipse + Maven 3 + Wildfly 9  

Tutorial 2 : Session Beans

Tutorial 3 : Solution Design

Tutorial 4 : Session Beans and Business Interfaces Projects

Tutorial 5 : Local View – Client and EJBs in the Same WAR  

Tutorial 6 : Remote View – Client and EJBs in the Same EAR  EJB 3 Remote View

Tutorial 7 : Remote View – Client and EJBs in Different WARs but Same Container

Tutorial 8 : Remote View – Client and EJBs in different Containers

Tutorial 9 : Standalone Client


How to invoke a Session Bean packaged in another WAR but deployed in the Same EAR?

Will the client need a Remote or Local View?

We will deploy the Client and the Session Beans in the same EAR, and use a JSF Session Scoped Managed Bean to inject/lookup the Session Beans.

Client and Session Beans in different WARs but Same EAR

1. Maven Artifacts

  • To create :
ejb3-remote-client-0-war ejb3-server-client-ear
  • Group Id : com.letsprog.learning
  • Artifact Id : ejb3-remote-client-0-war
  • Version : 0.0.1-SNAPSHOT
  • Packaging : war
  • Group Id : com.letsprog.learning
  • Artifact Id : ejb3-server-client-ear
  • Version : 0.0.1-SNAPSHOT
  • Packaging :ear
  • to improve :
jndi-lookup-util
  • Group Id : com.letsprog.learning
  • Artifact Id : jndi-lookup-util
  • Version : 0.0.1-SNAPSHOT
  • Packaging : jar
  • To reuse :
ejb3-server-impl
  • Group Id : com.letsprog.learning
  • Artifact Id : ejb3-server-impl
  • Version : 0.0.1-SNAPSHOT
  • Packaging : jar

The artifact ejb3-server-impl was implemented in this tutorial.

2. Improving jndi-lookup-util to invoke  a Remote View

We have already created this project in the previous tutorial.

Now we got to improve the LookerUp class to support Remoting JNDI Lookup :

3. Creating ejb3-remote-client-0-war

3.1. pom.xml

3.2. The JSF Session Scoped Managed Bean

3.3. The GUI

  • index.xhtml

  • quiz.xhtml

  • end.xhtml

4. Creating ejb3-server-client-ear

4.1. 1st Possible configuration

4.1.1. pom.xml

Remark 1 (Line 31) : Notice the instruction <applicationName>${project.artifactId}</applicationName> where we have eliminated the version placeholder. That is to eliminate version from the JNDI name of the EAR. Without this configuration we would have to use in our JNDI Lookup :

Instead of :

You can read more about Controlling JNDI Names.

Remark 2 (Line 33) : Since we are defining all our deployment configuration in pom.xml of the ear we are choosing to generate from; it the application.xml file (next you will discover what this file can have as a content 🙂 )

Remark 3 (Line 36) : As you know the artifact ejb3-server-war contains the session beans that will be invoked by the client. So logically this artifact must be deployed before any of its clients. That is why we will impose the respect of the modules order.

4.2. 2nd Possible configuration

4.2.1. pom.xml

4.2.2. application.xml

5. Deployment & Testing

You just need to deploy the artifact ejb3-server-client-ear, and verify that the quiz is reachable from the URL : http://localhost:8080/ejb3-remote-client-0-war/index.xhtml

Retro-Flower-Fire-2-iconOk! Now let’s move to the second example of Remote Client!