Java 如何从容器外部访问 Websphere 7.0 中定义的 JNDI 命名空间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9739965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access the JNDI namespace defined in the Websphere 7.0 from outside of the container?
提问by
I am tring to lookup the resource defined on the Websphere aplication server 7.0 from the out side of the Container with using the iiop protocol as below:
我正在尝试使用 iiop 协议从容器的外部查找 Websphere 应用程序服务器 7.0 上定义的资源,如下所示:
Java code for (RMI client)Test.jar:
(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();
}
}
Cmmand file to call the Test.jar:
调用Test.jar的命令文件:
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%
NOTE : Please not that I am runnig the client on my local machin and bootstrap host is : localhost and the port is 2809.
注意:请注意,我在本地机器上运行客户端,引导主机是:localhost,端口是 2809。
At the time of running the Test.jar code form the command file I am getting the following error:
在从命令文件运行 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
I have no idea that why this code is not able to instantiat the InitialContext(Hashmap env)
. This same code is running in Websphere application server version 5.1 but having problem in Websphere application server version 7.0.
我不知道为什么这段代码不能实例化InitialContext(Hashmap env)
. 相同的代码在 Websphere 应用程序服务器 5.1 版中运行,但在 Websphere 应用程序服务器 7.0 版中出现问题。
回答by Brett Kail
Using JARs from WAS_HOME/deploytool for the classpath is not supported. Try using the documented EJB thinclientwith WAS_HOME/runtimes/com.ibm.ws.ejb.thinclient_7.0.0.jar.
不支持将来自 WAS_HOME/deploytool 的 JAR 用于类路径。尝试将文档化的EJB 瘦客户端与 WAS_HOME/runtimes/com.ibm.ws.ejb.thinclient_7.0.0.jar 一起使用。