Avatar of vurity
 asked on

WAS5.x InitialContext issue


I am trying to do some lookups on the Websphere Appserver using the InitialContext and am getting the following Exception

Error : javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory [Root exception is java.lang.ClassCastException: com.ibm.websphere.naming.WsnInitialContextFactory]

The following is the code that I am using
Properties props = new Properties();
      props.put(Context.PROVIDER_URL, "iiop://localhost:26014/");
      // Create the initial context from the properties we just created
      Context initCtx= new InitialContext(props);

      out.println("initcontext: " + initCtx);
      System.out.println("initcontext: " + initCtx);
      Object o = initCtx.lookup("jdbc/somedatasource");
      out.println("object is:"+o);
      }catch(Exception e)
I am working on a Linux OS and this is the classpath for the appserver
ws.ext.dirs = /opt/WebSphere/AppServer/java/lib:/opt/WebSphere/AppServer/classes:/opt/WebSphere/AppServer/classes:/opt/WebSphere/AppServer/lib:/opt/WebSphere/AppServer/lib/ext:/opt/WebSphere/AppServer/web/help:/opt/WebSphere/AppServer/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime
Classpath = /opt/WebSphere/AppServer/properties:/opt/WebSphere/AppServer/properties:/opt/WebSphere/AppServer/lib/bootstrap.jar:/opt/WebSphere/AppServer/lib/j2ee.jar:/opt/WebSphere/AppServer/lib/lmproxy.jar:/opt/WebSphere/AppServer/lib/urlprotocols.jar
Java Library path = /opt/WebSphere/AppServer/java/bin/../jre/bin:/opt/WebSphere/AppServer/java/jre/bin/classic:/opt/WebSphere/AppServer/java/jre/bin:/usr/IBMdb2/V7.1/java12:/opt/WebSphere/AppServer/java/bin/../jre/bin:/opt/WebSphere/AppServer/java/jre/bin/classic:/opt/WebSphere/AppServer/java/jre/bin:/opt/WebSphere/AppServer/bin:/opt/mqm/java/lib:/opt/wemps/lib:/opt/WebSphere/AppServer/lib:/usr/lib

When I try the same code on my local WSAD it is working fine. I took care to change the port when I put it on the linux server, so that is taken care of.
Am I missing something in the classpath?

Thanks and Regards
Java App Servers

Avatar of undefined
Last Comment

8/22/2022 - Mon
Peter Kwan

Does this site help?


Also, please try to set your Classloader to Parent_last for your application.

    I am using the Parent_Last classloader option itself and I dont have any of the websphere related jars at EAR level or else where...

Thanks and Regards

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck