Link to home
Start Free TrialLog in
Avatar of vurity
vurity

asked on

WAS5.x InitialContext issue

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
Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

Does this site help?

http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=46&t=002318

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

ASKER

Hi
    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
Sri
ASKER CERTIFIED SOLUTION
Avatar of shinobun
shinobun

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial