wood burning stoves*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes my first ejb program and finding it hard to run ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "my first ejb program and finding it hard to run ?" Watch "my first ejb program and finding it hard to run ?" New topic

my first ejb program and finding it hard to run ?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924

i'm trying to run a simple hello world kind of ejb program in eclipse. here is what i did.

i created a new enterprise application project. after that there was an option of NEW MODULE . i clicked on it and it gave me option of creating default module. i created application client module and ejb module.


i have a POJI and a POJO which is a stateless bean as given below :

in the application client module i have :

package ejb3inaction.example;

import javax.ejb.EJB;

so in project explorer i have an enterprise application project with 2 modules viz. ejb module and client module. i right clicked enterprise project and clicked run on server. then i exported the application client module project as export > application client jar file. i placed the jar file in the location of appclient binary of glassfish. i invoked appclient - client Testclient.jar and it gave me error that it cannot find class HelloUser.

i have included ejb moduel project in build path of application module. Please help ?

if i dont create enterprise application project but just create ejb project and put all 3 files in the single project then it runs fine.

please help

thanks and regards

Frits Walraven
Creator of Enthuware JWS+ V6

Joined: Apr 07, 2010
Posts: 1629

Hi Gurpeet,

Trying to access an EJB from a Java SE project or the ACC (Application Client Container) is always a bit tricky as you need to configure some things manually. The best way is to test from a Servlet, as you are now quite familiar with Servlets. Injection of an EJB in a Servlet doesn't need any extra configuration.

Did you read the Oracle ACC article?

You can also try if the lookup from the JNDI (replace ApplicationClientContainerTest with your ear-project name and ApplicationClientContainerTestEJB with your EJB-project name) works:

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 721
Hi, I have a question.
This is not a URL,

How can the client remotely look up the HelloUserBean which implements a remote interface?
Frits Walraven
Creator of Enthuware JWS+ V6

Joined: Apr 07, 2010
Posts: 1629

It can do that because that is the default "address" of the EJB in the global JNDI.
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 721
I connected two computers via adhoc network.
On the server computer, I have this:

On my client computer, I ran http://123.456.78.90:8080/HelloApplication-war/HelloClientServlet from my Firefox browser, where 123.456.78.90 is replaced by my server's IP address.
It works and prints "Hello George" on the browser.

But on my client computer, I ran HelloClient, which is a standalone client, I got this error:

My conclusion: The standalone client cannot look up the address of the HelloApplication.ear file and cannot even find the HelloApplication-ejb.jar.
The remote servlet client can connect to the server over HTTP.

Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3253
The magic is in the Context. For a client to access remote bean, you need to first acquire a reference to the right context. The "right" context means, you need to pass in parameters (either through jndi.properties or a HashMap or some other API that I might not be aware of) that tell your context provider to connect to the naming server that with which your bean is registered. Just doing new InitialContext() cannot give you a reference to a remote bean because it has no idea about the beans existence.

Once you acquire the right context, the URL that you have mentioned will work.

You might want to go through a good book that explains this or search for articles online.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Frits Walraven
Creator of Enthuware JWS+ V6

Joined: Apr 07, 2010
Posts: 1629

If you are using Glassfish you can try the ACC, as I pointed out above:
The Application Client Container (ACC) includes a set of Java classes, libraries, and other files that are required for and distributed with Java client programs that execute in their own Java Virtual Machine (JVM). The ACC manages the execution of Java EE application client components (application clients), which are used to access a variety of Java EE services (such as JMS resources, EJB components, web services, security, and so on.) from a JVM outside the Oracle GlassFish Server.

The ACC communicates with the GlassFish Server using RMI-IIOP protocol and manages the details of RMI-IIOP communication using the client ORB that is bundled with it. Compared to other Java EE containers, the ACC is lightweight.

The difficulty of how to get the right Context, as Paul was pointing out, is handled by the ACC.
I agree. Here's the link: http://aspose.com/file-tools
subject: my first ejb program and finding it hard to run ?
Similar Threads
EJB simple client is not running
How to run Hello World example in Eclipse with Glassfish v3 as appserver
@EJB annotation from servlet and JBoss
Stateless session bean keeping state???
Problem facing while creating EJB3 application in Netbeans