| Author |
Head First Ejb -- Sample Program Exception
|
ashok ganesan
Ranch Hand
Joined: Jan 02, 2007
Posts: 50
|
|
hi everyone, i m using headfirst ejb and trying to run a sample program . As given in the book i deployed my application in java server when i run my client class file i got an exception like this... E:\projects\advice>java AdviceClient javax.naming.NoInitialContextException: Need to specify class name in environmen t or system property, or as an applet parameter, or in an application resource f ile: 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:19) at AdviceClient.main(AdviceClient.java:13) being a new to ejb i couldnot understand what the exzception is and how to resolve it .... if someone could help me out of it. thanks in advance ashok
|
 |
ashok ganesan
Ranch Hand
Joined: Jan 02, 2007
Posts: 50
|
|
my program is import javax.naming.*; import java.rmi.*; import javax.rmi.*; import javax.ejb.*; import headfirst.*; import java.lang.*; public class AdviceClient { public static void main(String[] arg) { new AdviceClient().go(); } public void go() { try{ Context ic = new InitialContext( ); Object o = ic.lookup("AdviceBean"); <--- error occurs hereAdviceHome home = (AdviceHome)PortableRemoteObject.narrow(o,AdviceHome.class); Advice advisor = home.create(); System.out.println(advisor.getAdvice()); }catch(Exception e) { e.printStackTrace(); } } }
|
 |
Sumit Malik
Ranch Hand
Joined: Jan 05, 2007
Posts: 84
|
|
Hi Ashok Ganesan, The runtime error which is thrown by your code is because you haven't defined default JNDI properites in your client jar. Other way around to this problem is that you can explicity set JNDI properties thorugh Initial Context though its inefficient approach. Do set JNDI properties in code and then try to run you code.... I hope these links would help you in better way.... JNDI reference Go through these links and hopefully you will get solution of your problem.... Cheers !!! Sumit Malik Sun JNDI reference J2EE JNDI reference
|
If at first you don't succeed, don't try skydiving
|
 |
ashok ganesan
Ranch Hand
Joined: Jan 02, 2007
Posts: 50
|
|
hi , as per the previous link i made changes in my program but i couldnot get the jndi.jar file which has the com.sun.enterprise.naming.SerialInitContextFactory class . i tried dowmloading file from sun site . but jndi 1.2.1 and jndi 1.1.2 donot have those files. with only those class files in my classpath i could run my program . thanks ashok
|
 |
Sumit Malik
Ranch Hand
Joined: Jan 05, 2007
Posts: 84
|
|
Hey Ashok which app server you are using for your application. If you are using glassfish(from SUN) then you can use appserv-rt.jar(you can find this jar in the lib directory of installed glassfish) in your client lib. This jar contains com.sun.enterprise.naming.SerialInitContextFactory class ..... Did you set jndi.properties in your client classpath ??? Do make these changes and try to run you application Cheers !!! Sumit MAlik
|
 |
Naveen Kumar
Ranch Hand
Joined: Dec 14, 2006
Posts: 35
|
|
Hi Ashok R you using WSAD or different IDE. Regards kumar
|
 |
Naveen Kumar
Ranch Hand
Joined: Dec 14, 2006
Posts: 35
|
|
Hi If you are using WSAD i will tell how to configure JNDI in EJB. Regards kumar
|
 |
 |
|
|
subject: Head First Ejb -- Sample Program Exception
|
|
|