*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Still having problem with my first EJB3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Still having problem with my first EJB3" Watch "Still having problem with my first EJB3" New topic
Author

Still having problem with my first EJB3

Mamadou Touré
Ranch Hand

Joined: Dec 27, 2007
Posts: 189
I'm still confused with how to interact with the JNDI, here is my simple code to display hello, so could someone tell me what's wrong ?

1 - error message tha I got
Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at sourceClient.HelloClient.main(HelloClient.java:21)

2 - My EJB class and interface:





3 - My EJB client


SCJP 5 (76%)
SCWCD 5 (86%)
SCBCD 5(70%)
--------------------
"The greatest glory in living lies not in never falling, but in raising every time we fall.".. Nelson Mandela
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi,

from a quick look your examples looks alright!

The problem is the JNDI lookup. You have to know the right lookup name and you most probably have to specify some system parameters which tell the client for example on which IP address and port it may connect to a JNDI provider.

Both of these things may depend on the application server (at least with EJB 3.0) you're using! So perhaps you can tell us which server it is or you can search yourself on the internet which are the correct settings for your server!

Marco
Mamadou Touré
Ranch Hand

Joined: Dec 27, 2007
Posts: 189
Thanks,

I'm using Glassfish server

Do I have to setup something on the server ?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi,

from the header of your code fragments I guess you used NetBeans to create the project. Perhaps it's the easiest way to understand the problem by having a look at this tutorial. In particular the section "Creating a Java Stand-Alone Client" will be helpful as it describes how to setup the JNDI parameters with a "jndi.properties" file on the classpath ;-)

Additionally it could be useful for debugging to show what's in the JNDI lookup of Glassfish as described here.

Marco
Sai Surya
Ranch Hand

Joined: Feb 08, 2006
Posts: 457

Hi Marco,

Perhaps you can try using name attribute for your @Stateless annotation and use that name in the JNDI look up. It worked for me in Glashfish app. server.



Sai Surya, SCJP 5.0, SCWCD 5.0, IBM 833 834
http://sai-surya-talk.blogspot.com, I believe in Murphy's law.
 
 
subject: Still having problem with my first EJB3
 
Similar Threads
Exception in thread "main" javax.naming.NoInitialContextException:
Calling and EJB3 from a servlet using DI
Persist problem
Hello world ejb3 problem
ejb3 with javaee client helloworld