Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes How to invoke an EJB3 from a simple client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to invoke an EJB3 from a simple client" Watch "How to invoke an EJB3 from a simple client" New topic
Author

How to invoke an EJB3 from a simple client

Jose Campana
Ranch Hand

Joined: May 28, 2007
Posts: 339
Good day you all!

It's fine to be posting here in the EJB forum!
I am new student of EJB3 Technology. And have previously worked with EJB2 only; I understand the development for version 3 is simplified; And I have been trying to create a Simple client for an EJB3, but the problem is that in every example, the client is deployed as part of the same Enterprise Application.
I want to know how Could I invoke a simple EJB3 (One Stateless with 1 method that outputs Hello for example) from a simple Java Class with a main method.
But, to reiterate a class that belongs to an entirely different project; A stand-alone Java SE project.



I need to know the necessary steps to make a call to an EJB3 from a code like the preceding Snippet I just posted. In version 2 it was required to have the client Stubs Generated by the Server; Do I need Stubs here also?
Please let me know what is the code to make the call also. (I'm assuming I still have to use a JNDI lookup)

Best Regards,
Jose
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Jose,

Feel free to look at the JBoss and GlassFish example code for EJB 3 in Action: http://www.manning.com/panda/. We have examples of what you are asking for.

Regards,
Reza
[ December 02, 2008: Message edited by: Reza Rahman ]

Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
Dheeman Basu
Greenhorn

Joined: Mar 17, 2009
Posts: 12
I have similar problem. I am working with chapter 2 example code of "EJB3 in Action".
I am using eclipse IDE 3.4 and JBoss 4.2.2 server.

I could successfully do the ANT build. But I have no clue how to run the clients. There are aparently two clients built chapter2-sfsb-client.jar and chapter2-slsb-client.jar. My questions are

1. How do I configure Eclipse run environment to run any of these two clients?
2. How do I run any of them from command line?
3. I tried to run them using appclient from Sun App Server 8.1 I . The appclient complains that there is no application-client.xml in client META-INF folders. This is true. I noticed that ant build script is attempting to copy application-client.xml from /etc folder to META-INF. But the file is missing in /etc folder. ( I downloaded JBOSS version of the examples.)

Please help.

Dheeman Basu
Jeffry Kristianto Yanuar
Ranch Hand

Joined: Oct 01, 2007
Posts: 759
I also have similar problem. From the code examples that Manning site, I notice that one important thing to invoke an EJB session bean completely from stand-alone client (not from app-client) is by using JNDI.

The question is, How do I know the JNDI name ?

I tried the examples in https://glassfish.dev.java.net/javaee5/ejb/examples/Sless.html.

The code samples in there said that the JNDI name is "ejb30.Sless" but I still couldn't call it with stand-alone client (the app-client works).

In the Manning code examples the sample lookup name is "java:comp/env/PlaceBid". This is very different in the glassfish example, in the glassfish example, there is no prefix "java:comp/env/".


Please help us, I'm also new in EJB 3. I'm so confused too.

Jeffry Kristianto Yanuar (Java Instructor) SCJP 5.0 SCJA SCJD


Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
The JNDI name used for EJB's are currently specific to the container. You'll have to look at the container's documentation to know what the JNDI name would be. JNDI names are being standardized in EJB 3.1/Java EE 6. You do not need to know the JNDI name of the EJB for most real-world use cases.

As to IDE support for our example code, we currently do not have the bandwidth to do it. Most IDE documentation does tell you how to setup and run a EJB 3/Java EE 5 project. Once you look through the code examples and have read the book, it should not be all that difficult to do (in fact, a few people have done exactly this already).

If you have specific questions on our code examples, I'll be happy to answer them.

Thanks,
Reza
 
 
subject: How to invoke an EJB3 from a simple client
 
Similar Threads
how to get Clients CPU information on Server using Java RMI
Classes
Stub classes for standalone EJB clients
Running a RMI Application
exception declaration