File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Hep to solve NoInitialContextException error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Hep to solve NoInitialContextException error" Watch "Hep to solve NoInitialContextException error" New topic
Author

Hep to solve NoInitialContextException error

PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I am doing an example from HF. I think I followed the instructions exactly as it is from HF. But I am not able to run the program. I am getting the following error:

C:\projects\advice>java AdviceClient
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:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at AdviceClient.go(AdviceClient.java:15)
at AdviceClient.main(AdviceClient.java:9)


My JNDI name and the name in the context lookup are the same. Any help is greately appreciated.
Thanks.
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I am in a deadlock. I cannot go anywhere unless somebody help me.
Please...
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Pradeep,

Did you try this?

http://www.coderanch.com/t/317367/EJB-JEE/java/Running-headfirst-ejb-st-chapter


I think, therefore I exist -- Rene Descartes
vikas prasad
Ranch Hand

Joined: Nov 06, 2005
Posts: 44
Hi Pradeep,
I will sugest you to check your path,
See all this problem have a root cause with the path varible you set.
if you tell how have you set class paths then i can try to help.
still

try this: SET ENVIRONMENT VARIABLES:
JAVA_HOME C:\jdk1.3.1_16
J2EE_HOME C:\j2sdkee1.3.1
CLASSPATH C:\j2sdkee1.3.1\lib\j2ee.jar;D:\Certification\projects\advice

CLASSPATH should contain your j2ee jar file as well as your application jar file.
just put directory path for AdviceAppClient.jar file ok.
and follow the instruction in the book.
$ javac -classpath %CLASSPATH%;AdviceAppClient.jar AdviceClient.java

$ java -cp %CLASSPATH%;AdviceAppClient.jar AdviceClient
Bingo
This is what I did and it works fine may be you can try the same.
vikas prasad


Vikas Prasad<br />SCJP 1.4 SCWCD1.4 SCBCD1.3
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I have the following in the env variable.
JAVA_HOME=C:\j2sdk1.4.2_06
CLASSPATH=C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;C:\Program Files\Altova\xmlspy\XMLSpyInterface.jar

When I execute the command to run,I specify the classpath in the command.
C:\projects\advice>java -cp .;C:\Sun\AppServer\lib\j2ee.jar;AdviceAppClient.jar AdviceClient

Do I still have to set my environment variables?

I don't have a J2EE_HOME environment variable. Where is it pointing to?

I get the error only when I run. I can compile.

Thank you very much.
[ November 28, 2005: Message edited by: PradeepPillai Pradeep ]
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
My environment variables are set now.

CLASSPATH=C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;C:\Program Files\Altova\xmlspy\XMLSpyInterface.jar
J2EE_HOME=C:\j2sdkee1.3
JAVA_HOME=C:\j2sdk1.4.2_06

I still get the same error. For other classpath dependencies I point to the right location with -cp as shown in the previous post.
SL Narasimhan
Greenhorn

Joined: Jul 19, 2005
Posts: 22
Even I faced a similar problem. I just added appserv-rt.jar to my classpath while running the application and everything went on fine.

Cheers,
Narasimhan


SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3<br />IBM Certified Solution Developer - WebSphere Portal 6<br />IBM WebSphere Portal 6 Deployment and Administration
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hep to solve NoInitialContextException error
 
Similar Threads
Error running the HF EJB AdviceClient with Weblogic Server
regarding EJB Deployment
NoInitialContextException :- running AdviceClient
getting error from AdviceClient code from Head First EJB book, pg 57
Running the headfirst ejb 1st chapter