John
John

Reputation: 477

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

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!

Upvotes: 2

Views: 13285

Answers (2)

Manglu
Manglu

Reputation: 11344

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.

Upvotes: 2

Udo Held
Udo Held

Reputation: 12548

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.

Upvotes: 2

Related Questions