wood burning stoves 2.0*
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
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, "com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new InitialContext(props);

It gives the following error.

javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory. Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:374)
at java.lang.ClassLoader.loadClass(ClassLoader.java:562)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:438)
at java.lang.ClassLoader.loadClass(ClassLoader.java:494)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:256)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:59)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:661)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:256)
at javax.naming.InitialContext.init(InitialContext.java:232)
at javax.naming.InitialContext.<init>(InitialContext.java:208)
at test.LocalTest.mail(LocalTest.java:46)
at test.LocalTest.main(LocalTest.java:35)

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: http://aspose.com/file-tools
subject: Problem finding InitialContext
Similar Threads
Websphere 6.1 JAR Deployment and AutoDeploy_v31 tool - VVV IMP
Geting exeption in JNDI
RAD6 datasource access using JNDI
Runtime Exception - could not connect to EJB server
help jboss