我在WAS上配置了:QueueConnectionFactory ---- jms/qcf
Queue ---- jms/queue
然后写了个简单的客户端程序:
public class TestJMS(){
public static void main(String arg[]){
Properties p = new Properties();
try{
System.out.println("Initial Context Factory");
p.put
(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
System.out.println("Provider URL");
p.put(Context.PROVIDER_URL,"iiop://localhost:2809");
System.out.println("Initial Context");
InitialContext ctx = new InitialContext(p); <------调用到这里抛出异常
...........
}catch(NamingException e){
e.printStackTrace();
}
}
}
异常:
javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory. Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:516)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:441)
at java.lang.ClassLoader.loadClass(ClassLoader.java:448)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:220)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:57)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:661)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:255)
at javax.naming.InitialContext.init(InitialContext.java:231)
at javax.naming.InitialContext.<init>(InitialContext.java:207)
................
------解决方法--------------------------------------------------------
com.ibm.websphere.naming.WsnInitialContextFactory这个类找不到,你没有把websphere的客户端使用的.jar包含在classpath中。