File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Websphere and the fly likes Problem finding InitialContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Problem finding InitialContext" Watch "Problem finding InitialContext" New topic

Problem finding InitialContext

Vishva Rajput

Joined: Sep 23, 2003
Posts: 5
I have a stand alone Java Application running on WSAD 5.1. How do i get the initialcontext???

I am using the code

Hashtable props = new Hashtable ();
props.put (Context.INITIAL_CONTEXT_FACTORY, "");
Context ctx = new InitialContext(props);

It gives the following error.

javax.naming.NoInitialContextException: Cannot instantiate class: Root exception is java.lang.ClassNotFoundException:
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at com.sun.naming.internal.VersionHelper12.loadClass(
at javax.naming.spi.NamingManager.getInitialContext(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.init(
at javax.naming.InitialContext.<init>(
at test.LocalTest.mail(
at test.LocalTest.main(

Please help.

Regards, Vishva
Vishy Raman

Joined: Jun 24, 2003
Posts: 5
Where is this java application file located? Try placing the file in EJB project and J2EE project. If the file is in Java client project - it wouldn't find the EJB context.

There could be some other ways to create the EJBContext - if you want to test it real quick, the above ways should work
Andre Mermegas
Ranch Hand

Joined: Jun 20, 2001
Posts: 158
Well thats a pretty obvious exception, you don't have the naming.jar in your classpath, you probably will need other dependencies as well from the websphere app\lib directory.

--=( Andre Mermegas )=--
Vishva Rajput

Joined: Sep 23, 2003
Posts: 5
Vishi / Andre,

It works fine the way you suggested. How come? Also I need to run it as a standalone application, JUnit, what do i need to do. Add naming.jar, and what else.

I agree. Here's the link:
subject: Problem finding InitialContext
It's not a secret anymore!