我想使用iiop协议从Container的外部查找Websphere aplication Server 7.0上定义的资源,如下所示:
(RMI客户端)Test.jar的Java代码:
public static void main(String[] args){
Hashtable<Object, Object> properties = new Hashtable<Object, Object>();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
properties.put(Context.PROVIDER_URL, "iiop://localhost:2809");
InitialContext intCt;
try {
InitialContext initCtx = new InitialContext(properties);
Object obj = intCt.lookup(JNDI_NAME);
}catch (NamingException namingE) {
System.out.println("Naming Exception occurred :");
namingE.printStackTrace();
}
}
调用Test.jar的Cmmand文件:
set appClassPath=C:\WebSphere\AppServer7.0\deploytool\itp\plugins\com.ibm.websphere.v7_7.0.1.v20090422_1423\wasJars\naming.jar;C:\WebSphere\AppServer7.0\deploytool\itp\plugins\com.ibm.websphere.v7_7.0.1.v20090422_1423\wasJars\namingclient.jar;C:\WebSphere\AppServer7.0\properties;C:\Batch\CommandFiles\JobServer\Test.jar C:\WebSphere\AppServer7.0\java\jre\bin\java -jar -cp "%appClassPath%" C:\Batch\CommandFiles\JobServer\Test.jar %Parameters%
注意:请注意,我在本地machin和bootstrap主机上运行客户端是:localhost,端口是2809。
在从命令文件运行Test.jar代码时,我收到以下错误:
javax.naming.NoInitialContextException: Failed to create InitialContext using factory specified in hashtable {java.naming.provider.url=iiop://localhost:2809, java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory} [Root exception is java.lang.NullPointerException] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:243) at javax.naming.InitialContext.initializeDefaultInitCtx(InitialContext.java:327) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:357) at javax.naming.InitialContext.internalInit(InitialContext.java:295) at javax.naming.InitialContext.(InitialContext.java:212) at com.uuic.ets.rmi.server.client.Client.main(Client.java:130) Caused by: java.lang.NullPointerException at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:235) ... 5 more
我不知道为什么这段代码无法实例化InitialContext(Hashmap env)
。此相同的代码在Websphere应用程序服务器版本5.1中运行,但在Websphere应用程序服务器版本7.0中存在问题。
答案 0 :(得分:1)
不支持使用WAS_HOME / deploytool中的JAR作为类路径。尝试将记录的EJB thinclient与WAS_HOME / runtimes / com.ibm.ws.ejb.thinclient_7.0.0.jar一起使用。