This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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
Author

AdviceClient

Thilina Annakkage
Greenhorn

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(AdviceClient.java:45)
at AdviceClient.main(AdviceClient.java:26)


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Thilina Annakkage
Greenhorn

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

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
env.put(Context.PROVIDER_URL,
"localhost:1099");
Context ic = new InitialContext(env);
Tim Tim
Greenhorn

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(NamingManager.java:6
52)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at AdviceClient.go(AdviceClient.java:23)
at AdviceClient.main(AdviceClient.java:14)
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialIni
tContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.jav
a:42)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
49)
Thilina Annakkage
Greenhorn

Joined: Dec 24, 2004
Posts: 27
The following link might help you with seting it up
http://www.developer.com/java/ejb/article.php/10931_2215571_4

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.
 
GeeCON Prague 2014
 
subject: AdviceClient