• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

my first ejb program and finding it hard to run ?

 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
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.

IN 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

 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

Regards,
Frits
 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It can do that because that is the default "address" of the EJB in the global JNDI.
 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

HTH,
Paul.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
It's just a flesh wound! Or a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic