aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes JNDI names for EJBs 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 "JNDI names for EJBs" Watch "JNDI names for EJBs" New topic
Author

JNDI names for EJBs

Debasish Ray Chawdhuri
Greenhorn

Joined: Feb 05, 2007
Posts: 24
Hi, i'm absolutely new to ejb, so this is a silly question. I can access the EJBs from web container using @EJB annotation. But, when i try to use JNDI, the server log shows that the JNDI name does not exist. I'm using glassfish. Can somebody tell me how the default jndi names are used in glassfish, and how i can modify and assign custom jndi names?


SCJP 1.5, SCWCD 1.4, SCBCD 5.0 It's the attitude, and not the aptitude, that determine one's altitude in life.
palla sridhar
Ranch Hand

Joined: Oct 15, 2007
Posts: 111
Hi Ray!
The JNDI configuration for glassfish server is contained in the library - appserv-rt.jar. So when you annotate the bean with @Stateless or @Stateful give the mapped name for the bean.
For e.g

then when you look up for the bean in the client provide the code as follows.

For e.g


where RemovableRemote is the Remote Interface,
Removable is the mapped name.


Thanks and Regards,
[url]www.techlikes.com[/url]
*Nothing is CONSTANT in life, except CHANGE*
Gladwin Burboz
Greenhorn

Joined: Feb 26, 2008
Posts: 25
Glassfish's "Using the Java Naming and Directory Interface" ( https://glassfish.dev.java.net/javaee5/docs/DG/beanr.html ) could be great help and don't forget to have a look at section "Accessing EJB Components Using the CosNaming Naming Context" ( https://glassfish.dev.java.net/javaee5/docs/DG/beanr.html#beanu )


<a href="http://www.sealordresortarnala.com" target="_blank" rel="nofollow">http://www.sealordresortarnala.com</a>
Debasish Ray Chawdhuri
Greenhorn

Joined: Feb 05, 2007
Posts: 24
Thanks! but it still does not work

Here is the EJB



Here is the Local interface



And here is the servlet



now i have used the following request parameters.. but none of them works

java:comp/env/TestSession

TestSession

i am not having any ejb-jar.xml
[ February 27, 2008: Message edited by: Debasish Ray Chawdhuri ]
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Is your servlet part of the same application as the EJB? If not, then it won't work because the EJB only exposes a local interface rather than a remote interface.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Debasish Ray Chawdhuri
Greenhorn

Joined: Feb 05, 2007
Posts: 24
Yes, its part of the same application.. that is the ejb and the web application are in the same ear file
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
You should not narrow the object returned from the JNDI lookup unless you have a remote interface.

More seriously, you must have the ejb-jar.xml file in your EAR. It is mandatory to have this deployment descriptor for the EJB.
Vusa Dube
Greenhorn

Joined: Apr 04, 2006
Posts: 1
Originally posted by palla sridhar:


then when you look up for the bean in the client provide the code as follows.

For e.g


where RemovableRemote is the Remote Interface,
Removable is the mapped name.


I know this may be laughable but I'm also very new at this. Do I need to import the EJB application in the client application i.e have the .ear? If not, how is class "RemovableRemote" visible to the client at compile time? I understand how it works for local client since they'll be sharing the same JVM, but for remote I'm really confused.
palla sridhar
Ranch Hand

Joined: Oct 15, 2007
Posts: 111
Hi Vusa!
Please check this link. http://www.netbeans.org/kb/60/javaee/ejb-glassfish-maven.html

In that tutorial, the following is quoted.
Using the @Stateless annotation mappedName attribute allows you to assign names which you can use to search the EJB bean through the remote client


So you can use the EJB from even the remote client, but you need to import the package name the EJB is in the .ear.!!
Debasish Ray Chawdhuri
Greenhorn

Joined: Feb 05, 2007
Posts: 24
You should not narrow the object returned from the JNDI lookup unless you have a remote interface.

More seriously, you must have the ejb-jar.xml file in your EAR. It is mandatory to have this deployment descriptor for the EJB.


I thought ejb-jar.xml is optional in EJB3.0 spec. However even using an ejb-jar.xml did not work.

what exactly do i write in my ejb-jar.xml when i already have all the information in annotations
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNDI names for EJBs
 
Similar Threads
EJB in WAR Accessible from Components in Other Modules?
How to call EJB using jsp in JBossenv
WSAD 5.1.0 - JNDI - Resource Ref. Could Not Be Located.
Unable to run web-client
Accessing EJB s remote interface through seperate web application