• Post Reply Bookmark Topic Watch Topic
  • New Topic

NoInitialContextException

 
andrew philip
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone help me out in fixing the above mentioned exception in my AdviceBean application? Please find below the exception details:

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

I got this exception when i tried to run the client. Pl find below the client code:


try
{
Properties props=System.getProperties();

Context ic= new InitialContext(props);

Object o=ic.lookup("Advisor");

AdviceHome home= (AdviceHome)

PortableRemoteObject.narrow(o, AdviceHome.class);

Advice advisor=home.create();
System.out.println(advisor.getAdvice());
}catch(Exception e)
{
e.printStackTrace();
}

I did try without passing the system properties to InitialContext and I got the same exception. I thought by passing environment properties , it would create initial context factory . But, it didn't help me either.
I have deployed enterprise bean(AdviceBean ) in Sun Application Server 8. Deployment was successful ...but couldnt run the client.

Could anybody help me out on this?

thanks,
andrew
 
Kunaal A Trehan
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Try doing this

Properties propObj=new Properties();
//WEBLOGIC SPECIFIC
propObj.put(Context.PROVIDER_URL,"t3://weblogicServer:7001");
propObj.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");

//Creating the initial context
InitialContext ctx=new InitialContext(propObj);

Only thing u need to modify the above properties
Then use ur initial context
It shd work

Kunal
 
andrew philip
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kunal,

Thanks for your response. Well, you know I'm using Sun Application Server 8. I guess the Context.PROVIDER_URL and Context.INITIAL_CONTEXT_FACTORY will be different for this server. How do I find these properties for Sun application Server 8 ? Hope to hear from you soon.

thanks,
andrew
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Here is the link :
http://developers.sun.com/sw/building/tech_articles/bindingas65.html

where I found the answer to your question. Here is the code on that page.

// Set initial context and URL properties
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://host_name:9010");

// Create initial context and lookup
Context initial = new InitialContext(env);
Object obj = initial.lookup("java:comp/env/ejb/simple");
SimpleHome home = (SimpleHome)
PortableRemoteObject.narrow(obj,SimpleHome.class);
 
Toby Eggitt
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the same thing, and added the stuff about the environment. That
fixed that problem, but you'll see another post of mine because having
found the previous posts describing this, I then found that I get an
exception at runtime in the call to "narrow." I'm using the RI (AS8) too,
so if you manage to make this work, please let me know as I'm beginning to
believe it's impossible.

Hmm, why would I believe that? Well, I next moved to trying the "converter"
application in the J2EE tutorial. This version is their own code,
downloaded with the book, so I can't have got much wrong. I find that the
app works from the web page, but that version trys to use the "appclient"
command, and that command complains that the client jar (created by AS8
just moments before) is bad! What's with that? If I try to launch the
application client by hand, I get the same problem with initial context
that you describe.

Cheers,
Toby
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!