We are migrating our code from WAS 8.0 to Liberty 17.0.0.1 version. While we try to test the application online functionality we are getting the below error,
java.lang.ClassNotFoundException:
com.ibm.websphere.naming.WsnInitialContextFactory
com.ibm.ws.jndi.internal.WASInitialContextFactoryBuilder
We also checked our ear file using Liberty Migration toolkit and we are getting severe in one of the jar,
Use the default values for the java.naming.factory.initial and java.naming.provider.url JNDI properties when you migrate to Liberty. The following WebSphere Application Server traditional values for these properties are not valid:
java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory
java.naming.provider.url=corbaloc:iiop:localhost:2809
When you use the InitialContext(Hashtable) constructor, remove these two properties. If no other properties are being used, you can use the default constructor.
If the properties file rule detects a jndi.properties file, check the properties in the file. Either remove the java.naming.factory.initial and java.naming.provider.url properties, or delete the file if none of the properties are needed.
Can some one help us on how to use default InitialContext. Please find the attached code which calls the jndi and context path,
import java.util.HashMap;
import java.util.Map;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* @class name JndiObjectLocator.java
* @author pkannan
* @creation date Nov 1, 2004
* @description
*/
public class JndiObjectLocator {
/** Intial context to the JNDI Tree */
private InitialContext ctx = null;
/** Object Cache */
private Map cache = null;
//Object used to log messages
private static final IBwLog bwLog =
BwLogFactory.create(BwLogUtil.getClassName());
/**
* Creates a new JndiObjectLocator object.
*
* @throws BOBRuntimeException When Initial Context creation fails.
*/
public JndiObjectLocator() throws BOBNestedRuntimeException {
cache = new HashMap();
try {
ctx = new InitialContext();
System.out.println("CTX:" +ctx);
} catch (NamingException ne) {
bwLog.error(EVENTS.INITIALIZE, "Context Initialization Failure"+BwLogUtil.stackToStr(ne));
throw new BOBNestedRuntimeException(
"Context Initialization Failure",
ne);
}
}
/**
* Fetches any Object bound in JNDI.
*
* @param jndiName JNDI Name of the Object to be retrieved.
*
* @return Object bound to the given JNDI name.
*
* @throws ObjectLookUpException When JNDI lookup fails for any reason.
*/
public Object fetch(String jndiName) throws ObjectLookUpException {
Object obj = cache.get(jndiName);
System.out.println("JNDI:" +jndiName);
if (obj == null) {
try {
if (ctx != null) {
obj = ctx.lookup(jndiName);
if (obj != null && cache.get(jndiName) == null) {
synchronized (cache) {
cache.put(jndiName, obj);
}
}
} else {
bwLog.error(
EVENTS.INITIALIZE,
"Context Initialization Failure");
throw new BOBRuntimeException("Context Initialization Failure");
}
} catch (NamingException ne) {
bwLog.error(
EVENTS.JNDI_LOOKUP,
"Context Initialization Failure"+BwLogUtil.stackToStr(ne));
throw new ObjectLookUpException(
"BOB DataSource Lookup Failure",
ne);
}
}
return obj;
}
/**
* Closes the JNDI context.
*
* @throws BOBRuntimeException When IntialContext fails to close.
*/
public void destroy() throws BOBNestedRuntimeException {
try {
ctx.close();
} catch (NamingException ne) {
bwLog.error(EVENTS.INITIALIZE, "Naming Context Closing Exception"+BwLogUtil.stackToStr(ne));
throw new BOBNestedRuntimeException(
"Naming Context Closing Exception",
ne);
}
}
}