aspose file tools*
The moose likes BEA/Weblogic and the fly likes How to call a EJB3 from a EJB3 present in a different EAR. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "How to call a EJB3 from a EJB3 present in a different EAR." Watch "How to call a EJB3 from a EJB3 present in a different EAR." New topic
Author

How to call a EJB3 from a EJB3 present in a different EAR.

rohit goyal
Greenhorn

Joined: Jul 16, 2008
Posts: 3
I am working with EJB 3.0 in which we don't require deployment descriptors... EJB 3.0 has given a feature of dependency injection which will automatically inject the dependeny if you try to look up a JNDI or resource present in the same EAR....

But i am not able to call a EJB from a EJB resides in the other EAR package...

I have 2 EAR packages....

SampleEJB301
+ com.ibm.sample
IEchoSample301
EchoSample301 (Implementation of the IEchoSample301)
+ META-INF
ejb-jar.xml
weblogic-ejb.jar.xml

SampleEcho301 & SampleEcho2Client has been packaged into a EAR SampleEAR1
---------------------------------------------------------------------------
SampleEcho2Client
+ com.ibm.sample
IEchoSample302

SampleEJB302
+ com.ibm.sample
EchoSample302 (Implementation of the IEchoSample302)
+ META-INF
ejb-jar.xml
weblogic-ejb.jar.xml

SampleEcho2Client & SampleEcho302 EJB has been packaged into a EAR SampleEAR2



Now i want to call EchoSample302 from EchoSample301...

Can anybody help me to find the solution for this.. I tried to find a lot on google but not able to find any solution....

Error resolving ejb-ref 'echoSample302' from module 'SampleEJB301.jar' of application 'SampleEARa'. The ejb-ref does not have an ejb-link and the JNDI name of the target bean has not been specified. Attempts to automatically link the ejb-ref to its target bean failed because no EJBs in the application were found to implement the 'com.ibm.sample.IEchoSample303' interface. Please link or map this ejb-ref to its target EJB and ensure the interfaces declared in the ejb-ref are correct.

My Code
------

@Stateless(name="echoSample301")
public class EchoSample301 implements IEchoSample301 {
@EJB(name="echoSample302")
private IEchoSample302 echoSample302;

public void setEchoSample302(IEchoSample302 echoSample302){
this.echoSample302 = echoSample302;
}

public IEchoSample302 getEchoSample302(){
return echoSample302;
}

public void echo301() {
System.out.println("Hello Echo301");
echoSample302.echo302();
}
}


@Stateless(name="echoSample302")
public class EchoSample302 implements IEchoSample302 {

public void echo302() {
System.out.println("Hello Echo302");
}
}
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

Rohit,
Welcome to JavaRanch!

I'm not sure if you can use an annotation if you set up a remote ejb jar reference (in the ejb-jar.xml). You can always do an "old fashioned" JNDI lookup to lookup the remote bean.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jerwin Louise Uy
Ranch Hand

Joined: Oct 27, 2007
Posts: 75
Deployment descriptors in EJB 3.0 is optional. During deployment, it creates a global JNDI name using the fully qualified class name of your session beans by default. (Note - You have to consult how the app server maps your session bean because this may depend on the implementation of the app server. Glassfish uses the fully qualified name of the class)

Therefore, JNDI lookup or even DD is possible in different EAR because they can refer to a global JNDI name.

Regards.


Uy Jerwin Louise Vergara
Junior Developer / Research and Development at Incuventure Partners Corporation
email: jerwin.uy@incuventure.net
rohit goyal
Greenhorn

Joined: Jul 16, 2008
Posts: 3
Hi Jeanne,

I've used the remote interface to call a EJB from other EJB resides in a different EAR and it's working fin... But I have found a code which is very specific to WebSphere and it is calling a EJB form the other using the annotations even after they are in different jars..

In ibm-bind-jar.xml they have definded some binding names with the absolute location of the nodes and cell of the WAS.. And it is working fine on WAS but i havn;t found any way on weblogic like this...

I m quite new to WebLogic so I m nnot aware how to migrate the same ibm specific xml on WebLogic...

If you have any idea or can give me some sample to access a EJB from a different one in a different EAR using xml or any other way without using lookup code that will be really helpful..

Thanks in Advance
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

Rohit,
That WebSphere extension might be what I'm thinking of. I'm going to move this to our WebLogic forum where someone might know how to do so in WebLogic.
 
Don't get me started about those stupid light bulbs.
 
subject: How to call a EJB3 from a EJB3 present in a different EAR.