troubleshooting Question

WAS5.x InitialContext issue

Avatar of vurity
vurity asked on
Java App Servers
3 Comments1 Solution734 ViewsLast Modified:
Hi,

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.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
      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);
      try{
      Object o = initCtx.lookup("jdbc/somedatasource");
      out.println("object is:"+o);
      }catch(Exception e)
      {
      e.printStackTrace();
      out.println(e.getMessage());
      }
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
Sri
ASKER CERTIFIED SOLUTION
shinobun

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros