This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Access EJB from Java Application   Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Access EJB from Java Application   " Watch "Access EJB from Java Application   " New topic
Author

Access EJB from Java Application

shashi wagh
Ranch Hand

Joined: Oct 30, 2008
Posts: 38
Hi.........

I have a EJB 3 application which is deployed on JBoss server.

I have develop a java application which access the EJB. It works fine when both application on same machine.

My problem is I want to place EJB @ centralized location and client @ remote places.

If any changes happen to EJB it should not required to rebuild the jar @ every places.

I am calling EJB like this



When I put it on different machine It will not get MyBeanRemote class cause it is not @ every client machine

Please suggest something

I want to extend this application to SWING and calling EJB from Swing app. so that GUI is @ client side and Business Logic is @ server.


Thanks
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

>>My problem is I want to place EJB @ centralized location and client @ remote places.

This is one of the problem that EJB tries to solve.

MyBeanRemote should be an interface.. and it must be available at the client in the remote machines.


- Chinna
shashi wagh
Ranch Hand

Joined: Oct 30, 2008
Posts: 38
Following are the Steps which I have performed

1 Created EJB 3 application in Myeclipse
2 Deployed it on JBoss 4.2
3 Created a Java Application in MyEclipse
4 Configure the build path to access the EJB application
5 Start the Server
6 Run the Application in MyEclipse.
7 It Works Fine.


Now I export the Client application to Jar --------> TestClient.jar
Now I export the Interfaces in EJB application to --------> TestBeanInterface.jar

Following is the command I used to run the Client
java -cp "TestBeanInterface.jar;jbossall-client.jar";TestClient.jar com.gts.ejbdemo.client.MyBeanClient

N got the following output



Tell me what is I am doing wrong.........

But when I export all ejb application to jar It works................

Edited by: shashiwagh on Feb 26, 2010 4:53 AM
Kai Wähner
Ranch Hand

Joined: Sep 16, 2009
Posts: 76
Now I export the Client application to Jar --------> TestClient.jar
Now I export the Interfaces in EJB application to --------> TestBeanInterface.jar

Following is the command I used to run the Client
java -cp "TestBeanInterface.jar;jbossall-client.jar";TestClient.jar com.gts.ejbdemo.client.MyBeanClient


Simply using a java client and including the ejb jar is not enough...

There are two possibilities to call EJBs from a remote client, which is not deployed at the application server:
1) Use an application client (JEE implementations offer an ejb container, web container and application client container - the latter one is for using jee features such as dependency injection from a J2SE client)
2) Get the ejb via JNDI lookup. you have to configure the server url, port and so on.


My IT-blog about my experiences with: Java / JEE, IT Conferences and IT Certifications

 
Don't get me started about those stupid light bulbs.
 
subject: Access EJB from Java Application