• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Initial Context Exception

 
Vijay Gade
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am doing the first given exactly as mentioned in the Head First EJB. I am still getting the following error when I try to compile the AdviceClient.java:
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:19)
at AdviceClient.main(AdviceClient.java:11)

I am using java version 1.4.2.12 and j2ee 1.3.1 in windows xp.
I even added AdviceAppClient.jar to the CLASSPATH.

Any help please? As you can obviously see, I am very much new to EJBs.

Thanks,
-Vijay
 
Vijay Gade
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant "run" AdviceClient, not "compile". Sorry about that.

-Vijay
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set the security ploicy as a argument to your java Djava.security.policy=<<filepath>>
 
Vijay Gade
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vidyasagar,

I am now facing a new problem. I initially was using OC4J's j2ee/home/lib/ejb.jar. Then, I removed that ejb.jar from my CLASSPATH, and added Sun's home/lib/j2ee.jar. I compiled the classes, and deployed the application (just like in HF). I then added my AdviceAppClient.jar to the CLASSPATH, and compiled the AdviceClient.java, and it comiles fine.

The problem starts when I try to run the client, at exactly the following line,
Object o = ic.lookup ("Advisor");

and the error is:

I am now more confused!! And as for your question, no, I did not include the properties file, because I do not know what to include. Could you please help me out?

Thanks a lot!

-Vijay
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi vijay

i think now you have problem in passing properties to ypur intial context.

Read the server document which guides you what are all properties you need to set for intial context.

Regarding security policy:

create a .policy file in your system

If you are using eclipse,you can set as default VM arguments in installed JRE tab.you should set like this

-Djava.security.policy=C:\client.policy(policy file name is userdefined)

create a file(client.policy) with below contents

grant {
permission java.security.AllPermission;
}

I am also newbie to EJB and still learning things.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic