java eclipse glassfish 3,客户端错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5997504/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 13:53:40  来源:igfitidea点击:

eclipse glassfish 3 , client error

javaglassfish-3

提问by user595234

I am using latest Eclipse to develop EJB 3 under Glassfish 3. I create a new Glassfish server instance in the Eclipse, write a simple EJB, deployed and succeeded.

我正在使用最新的 Eclipse 在 Glassfish 3 下开发 EJB 3。我在 Eclipse 中创建了一个新的 Glassfish 服务器实例,编写了一个简单的 EJB,部署并成功。

Now I write a client, but it always give me error like this

现在我写了一个客户端,但它总是给我这样的错误

java.lang.RuntimeException: Orb initialization erorr
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:148)
    at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
    at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.client.Test.main(Test.java:22)
Caused by: java.lang.NullPointerException
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:120)
    ... 8 more
Exception in thread "main" javax.naming.NamingException: Lookup failed for 'helloRemote' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.client.Test.main(Test.java:22)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is java.lang.RuntimeException: Orb initialization erorr]
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:352)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
    ... 3 more
Caused by: java.lang.RuntimeException: Orb initialization erorr
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:148)
    at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
    at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
    ... 4 more
Caused by: java.lang.NullPointerException
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:120)
    ... 8 more

the client code is this

客户端代码是这样的

Properties props = new Properties();
        props.setProperty("java.naming.factory.initial",  "com.sun.enterprise.naming.SerialInitContextFactory");
        props.setProperty("java.naming.factory.url.pkgs",  "com.sun.enterprise.naming");
        props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");


         InitialContext ic = new InitialContext(props);

         HelloRemote remote = (HelloRemote) ic.lookup("helloRemote");
         System.out.println(remote.echo("john"));

Do you know why ? is it "com.sun.enterprise.naming.SerialInitContextFactory" not in the classpath ?

你知道为什么吗 ?是不是“com.sun.enterprise.naming.SerialInitContextFactory”不在类路径中?

The source code is here http://www.mediafire.com/file/278rc1tpip0rjku/EJBApp2.rar

源代码在这里 http://www.mediafire.com/file/278rc1tpip0rjku/EJBApp2.rar

I appreciate your help.

我感谢您的帮助。

回答by Nico Baps

To solve this issue, you just need to add external jar "appserv-rt.jar" in the buildpath of the client.

要解决这个问题,您只需要在客户端的构建路径中添加外部jar“appserv-rt.jar”。

You can find it in the folder ...\glassfishv3\glassfish\lib

您可以在文件夹 ...\glassfishv3\glassfish\lib 中找到它

Or create a package with this jar and all its dependencies to add it in the BP

或者用这个jar包和它的所有依赖创建一个包,把它添加到BP中

This is my code

这是我的代码

InitialContext ctx = new InitialContext();
HelloWorld helloWorldRemote = (HelloWorld) ctx.lookup("ejb/helloWorldBeanJndiName");
System.out.println(helloWorldRemote.sayHello());

Without the jar file, i got the same error and with I get "Hello" in the console.

没有 jar 文件,我遇到了同样的错误,并且在控制台中出现了“Hello”。

回答by Snelders

Judging from the properties you set this must be a standalone client.

从您设置的属性来看,这必须是一个独立的客户端。

Make sure you include the gf-client.jar to your classpath for this to work. (glassfish\lib\gf-client.jar)

确保将 gf-client.jar 包含到类路径中以使其正常工作。(glassfish\lib\gf-client.jar)

You also don't need to set the properties you set. To specify a non-localhost location of your server or alternative port however you might set:

您也不需要设置您设置的属性。要指定服务器的非本地主机位置或替代端口,您可以设置:

prop.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
prop.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

You also might want to go over "How do I access a Remote EJB component from a stand-alone java client?" at: http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

您可能还想了解“如何从独立的 Java 客户端访问远程 EJB 组件?” 在:http: //glassfish.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

回答by Fosters

Seems to me like your trying to establish a connection from an application that is not deployed on your server which handles the connnectionpool

在我看来,您尝试从未部署在处理连接池的服务器上的应用程序建立连接

回答by nirgal

I had similar error:

我有类似的错误:

java.lang.RuntimeException: Orb initialization erorr at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:180)

which was caused by

这是由

java.lang.NullPointerException at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:152)

My solution was to add jar that contains GlassFishORBFactoryImpl.class that implements the GlassFishORBHelper interface.

我的解决方案是添加包含实现 GlassFishORBHelper 接口的 GlassFishORBFactoryImpl.class 的 jar。