Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown


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:
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(
at AdviceClient.main(

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

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();
}catch(Exception e)

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?

Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Try doing this

Properties propObj=new Properties();

//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

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

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.

Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here is the link :

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.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)
Ranch Hand
Posts: 68
  • 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.

She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic