Web applications 如何从独立客户端调用远程EJB

Web applications 如何从独立客户端调用远程EJB,web-applications,jakarta-ee,Web Applications,Jakarta Ee,我在weblogic服务器上部署了EJB。我想从独立应用程序(瘦客户机)访问这些EJB 好的。。。我自己找到的。:) 下面是我用来从瘦客户机连接到远程EJB的代码 Hashtable env = new Hashtable(5); env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); //Assuming weblogic server is running on localho

我在weblogic服务器上部署了EJB。我想从独立应用程序(瘦客户机)访问这些EJB

好的。。。我自己找到的。:)

下面是我用来从瘦客户机连接到远程EJB的代码

 Hashtable env = new Hashtable(5);
 env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
 //Assuming weblogic server is running on localhost at port 7001
 env.put(Context.PROVIDER_URL, "t3://localhost:7001");

 Context ic = new InitialContext(env);

 //obtain a reference to the home or local home interface
 FooHome fooHome = (FooHome)ic.lookup("MyBeans/FooHome");

 //Get a reference to an object that implements the beans remote (component) interface
 Foo foo = fooHome.create();

 //call the service exposed by the bean
 foo.shoutFoo()

这对我很有效。

如果这对你有效,你应该接受你自己的答案。如果你使用
weblogic.jndi.WLInitialContextFactory
这意味着你必须只从获取一些weblogic库的客户端调用EJB,wich可能没有那么薄。您应该在finally block中关闭初始上下文。上面的代码是我从命令行java程序(publicstaticvoidmain)运行的,下面是错误。请建议。线程“main”javax.naming.NoInitialContextException中的异常:无法实例化类:weblogic.jndi.WLInitialContextFactory[根异常为java.lang.ClassNotFoundException:weblogic.jndi.WLInitialContextFactory]由以下原因引起:java.lang.ClassNotFoundException:weblogic.jndi.WLInitialContextFactory