gpt4 book ai didi

java - 如何从容器外部访问Websphere 7.0中定义的JNDI命名空间?

转载 作者:搜寻专家 更新时间:2023-11-01 03:27:27 29 4
gpt4 key购买 nike

我正在尝试使用 iiop 协议(protocol)从容器外部查找在 Websphere 应用程序服务器 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的命令文件:

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.jarC:\WebSphere\AppServer7.0\java\jre\bin\java -jar -cp "%appClassPath%" C:\Batch\CommandFiles\JobServer\Test.jar %Parameters%  

注意:请注意,我在本地机器上运行客户端,引导主机是: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 版中出现问题。

最佳答案

不支持将 WAS_HOME/deploytool 中的 JAR 用于类路径。尝试使用已记录的 EJB thinclient使用 WAS_HOME/runtimes/com.ibm.ws.ejb.thinclient_7.0.0.jar。

关于java - 如何从容器外部访问Websphere 7.0中定义的JNDI命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9739965/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com