Cannot instantiate class: com.ibm.Websphere.naming.WsnInitialContextFactory

10,712

Solution 1

The WebSphere Application Server Community Edition isn't a real WebSphere application server. Its a "pimped" Apache Geronimo.

I wouldn't count on seeing any IBM classes in the Community Edition that where present in your AIX WebSphere.

I guess your options are:

  • Throw everthing IBM specific out.
  • Get at least the Express Edition.

Check the WAS edition comparison.

Solution 2

com.ibm.websphere.naming.WsnInitialContextFactory is WebSphere Application Server specific class.

As stated by Udo and others, WebSphere Community Edition is a different product altogether.

You have not only changed the run time OS from AIX to Windows but have changed the run time engine to another provider.

If the application contained code like this which is specific to the run time (WAS) in your case, then they will obviously not work when they are ported to another Java EE container (in this case WAS- CE which is actually based on Apache Geronimo Server).

As mentioned by Udo, there is no need to explicitly state the InitialContextFactory provider in the code these days. This used to be true in the past 5-6 years ago where the application developers had to explicitly state these. If you are looking at an object in a JNDI server which is hosted by the same server, there is no need to state this.

It is required when you run on WAS CE and looking at the JNDI server that is running on another WAS (regular IBM WAS not a CE )then this code is indeed required and you would need to ensure that those classes are present in your WAS CE run time CLASSPATH.

Share:
10,712
John
Author by

John

Updated on June 04, 2022

Comments

  • John
    John about 2 years

    I have to port a web application from AIX to windows server, but it throws exception like his on the newly installed IBM WebSphere Community Edition in windows like this:

    javax.servlet.ServletException: javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory [Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory in classloader...
    

    Tracing the code and nailed down to be caused by this code:

        Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
        Context jdbcCtx = new InitialContext(env);  
    

    The AIX Websphere is the full WebSphere Application Server while the windows one is Community Edition. I'm not sure what differences if any.

    Can anyone help to to fix that? Thanks!

    • Timmo
      Timmo over 12 years
      The class you are trying is nowhere to be found. Maybe they changed the class name or package of the InitialContextFactory implementation
  • John
    John over 12 years
    thanks for your reply. How can throw IBM specific out? Is there any generic one that can replace "com.ibm.websphere.naming.WsnInitialContextFactory" and work on both versions? Express is not an option as need to be free, trial not ok.
  • Udo Held
    Udo Held over 12 years
    I've got no clue what the "com.ibm.websphere.naming.WsnInitialContextFactory" is good for. You could try "Context jdbcCtx = new InitialContext();". You would also have to check if other IBM specific stuff is used elsewhere.
  • dbreaux
    dbreaux over 12 years
    Agree. Why are you specifying the InitialContextFactory class at all? Using the default provided by the J2EE server should work, in particular for objects defined within that server.
  • John
    John over 12 years
    That code is not done by me and indeed i'm newbie to websphere. While porting to windows, i'm hesitate to remove working code on AIX. My target is to make minimum changes to allow same code to run on both platforms. Thanks all of you for the nice suggestions, will check it out tomorrow~
  • John
    John over 12 years
    Thanks for the reply, the decision to port from AIX to Windows as well as changing the engine was made by an unknowledgable manager and assigned that task to me, which also unknowledgable in websphere too. I need to connect to another JNDI server, not the local one. I still struggling on how to connect without com.ibm.xxx, any help would be very appreciated!