客户端运行不了,急!!!

h_q_l 2005-03-06 03:14:56
我用SUN公司的J2EE服务器部署了一个session bean,JNDI中名称为ConverterBean

我的客户端的写法如下:

Context initial = new InitialContext();
Object objref= initial.lookup("java:comp/env/ejb/ConverterBean");

ConverterHome home =
(ConverterHome) PortableRemoteObject.narrow(objref,
ConverterHome.class);

Converter currencyConverter = home.create();


使用java运行的时候总提示我

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

要如何修改可以运行?
...全文
89 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
h_q_l 2005-03-06
  • 打赏
  • 举报
回复
我修改了代码,加上了几句

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://127.0.0.1:4848");

Context initial = new InitialContext(env);
Object objref= initial.lookup("java:comp/env/ejb/SimpleConverter");

ConverterHome home =(ConverterHome) PortableRemoteObject.narrow(objref,
ConverterHome.class);

Converter currencyConverter = home.create();

错误转换成如下:

javax.naming.CommunicationException: Cannot connect to ORB [Root exception is org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 208 completed: Maybe]
wang_zheng_wz 2005-03-06
  • 打赏
  • 举报
回复
magic,如果你不设置initial context的参数:javax.naming.Context.INITIAL_CONTEXT_FACTORY和javax.naming.Context.PROVIDER_URL,谁知道你要访问哪个服务器的jndi

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧