Meaningless Drivel is fun!*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes AdviceClient 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 "AdviceClient" Watch "AdviceClient" New topic


Thilina Annakkage

Joined: Dec 24, 2004
Posts: 27
I am trying to run AdviceClient as described in page 57 og HeadFirst EJB, using the following command

java %CLASSPATH% AdviceClient
My CLASSPATH=c:\java\projects\advice\AdviceAppClient.jar;c:\j2sdkee1.3.1\lib\j2ee.jar;.

I get the following error. What am I doing wrong? Please help. I did everything described in the book up to page 57.

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(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at AdviceClient.go(
at AdviceClient.main(

SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Thilina Annakkage

Joined: Dec 24, 2004
Posts: 27
I figured it out. I had to do the following

Hashtable env = new Hashtable();
Context ic = new InitialContext(env);
Tim Tim

Joined: Nov 20, 2004
Posts: 10
I got the same error, but when I use ur solution, but I got following exception! Can you pls gimme some hints and explaination why to cause that? as I am quite new to EJB! Thank you!


javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundE
xception: com.sun.enterprise.naming.SerialInitContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.init(
at javax.naming.InitialContext.<init>(
at AdviceClient.go(
at AdviceClient.main(
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialIni
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.jav
at javax.naming.spi.NamingManager.getInitialContext(
Thilina Annakkage

Joined: Dec 24, 2004
Posts: 27
The following link might help you with seting it up

Which paramters you pass to the InitailContext() constructor depend on which server you are using.
For example, if you are using JBoss, then use the following code

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost:1099");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming rg.jnp.interfaces");
Context ctx = new InitialContext(env);
Lahiru Abeydeera
Ranch Hand

Joined: Nov 05, 2004
Posts: 44
No You can get that error even if you are using Sun RI. The problem is The jar file which has the class com.sun.enterprise.naming.* are not in your ClassPath. Add <SUN APP SERVER>/lib/appsrv-rt.jar into your class path at runtime. no need to do it at compile time.
subject: AdviceClient
Similar Threads
Not able to run the AdviceClient program mentioned in Chapter 1 of Head First EJB
Head First EJB abend page 58 (run the client)
Head First -AdviceApp (page58) - Runtime error
Head First EJB - JNDI Error
For AdviceClient Application Pg:57HKEJB