Java EE 问题集锦: Root exception is java.lang.RuntimeException:&nb
(2013-12-11 13:58:56)
标签:
javaee问题集锦
ejb3
glassfish
jndi
orbinitializationero
|
分类:
Java-EE
|
Java EE 问题集锦:
Root exception is java.lang.RuntimeException: Orb initialization
erorr
【问题描述】:
最近觉得有必要亲自实践下ejb的最简单的例子,果然问题嗷嗷多,如下:
javax.naming.NamingException: Lookup failed for 'TestServiceBean'
in
SerialContext[myEnv={java.naming.provider.url=http://localhost:3700,
java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory,
java.naming.factory.url.pkgs=com.sun.enterprise.naming,
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl}
[Root exception is javax.naming.NamingException: Unable to acquire
SerialContextProvider for
SerialContext[myEnv={java.naming.provider.url=http://localhost:3700,
java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory,
java.naming.factory.url.pkgs=com.sun.enterprise.naming,
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl}
[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
org.cy.client.TestServiceTest.TestSayHello(TestServiceTest.java:34)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at
java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at
org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at
org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.naming.NamingException: Unable to acquire
SerialContextProvider for
SerialContext[myEnv={java.naming.provider.url=http://localhost:3700,
java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory,
java.naming.factory.url.pkgs=com.sun.enterprise.naming,
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl}
[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)
... 26
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)
... 27
more
Caused by: java.lang.NullPointerException
at
org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:120)
... 31
more
Test.java:
...
@Test
public void
TestSayHello() throws NamingException {
Properties p
= new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
p.setProperty(Context.PROVIDER_URL, "http://localhost:3700");
Context
context = new InitialContext(p);
TestService ts =
(TestService)context.lookup("org.cy.services.TestService");
System.out.println(ts.sayHello()); //Hello EJB!
}
...
【解决方案】:
引用gf-client.jar,并且是指向glassfish中的..\glassfish3\glassfish\lib下的
【问题分析】:
很容易看出来是Context初始化有问题,以至于后边的lookup都没法掉。
你得保证你的classpath中有引用gf-client.jar,
特别注意这里的引用jar一定是指向glassfish中的..\glassfish3\glassfish\lib下的,
这样他会在添加classpath顺便填加相关的jar包。
如果你打开gf-client.jar下META-INF/MANIFEST.MF文件时就会发现如下信息(想必你已经知道我要说些什么了,
当然你也是可以手动添加这些jar到你的classpath来代替gf-client.jar,反正随便你的):
Class-Path:
../modules/woodstox-osgi.jar ../modules/jtype.jar ../modul
es/tools.jar ../modules/glassfish-corba-asm.jar
../modules/glassfish-
corba-codegen.jar
../modules/glassfish-corba-csiv2-idl.jar ../modules
/glassfish-corba-internal-api.jar
../modules/glassfish-corba-newtimer
.jar ../modules/glassfish-corba-omgapi.jar
../modules/glassfish-corba
-orb.jar
../modules/glassfish-corba-orbgeneric.jar ../modules/auto-de
pends.jar ../modules/config.jar
../modules/config-types.jar ../module
s/hk2.jar ../modules/hk2-core.jar
../modules/osgi-adapter.jar ../modu
les/grizzly-comet.jar
../modules/grizzly-config.jar ../modules/grizzl
y-framework.jar ../modules/grizzly-http.jar
../modules/grizzly-http-s
ervlet.jar ../modules/grizzly-lzma.jar
../modules/grizzly-portunif.ja
r ../modules/grizzly-rcm.jar
../modules/grizzly-utils.jar ../modules/
grizzly-websockets.jar ../modules/javax.mail.jar
../modules/pkg-clien
t.jar ../modules/jaxb-osgi.jar
../modules/activation.jar ../modules/e
l-api.jar ../modules/jaxrpc-api-osgi.jar
../modules/endorsed/jaxb-api
-osgi.jar ../modules/junit.jar
../modules/javax.persistence.jar ../mo
dules/org.eclipse.persistence.antlr.jar
../modules/org.eclipse.persis
tence.asm.jar
../modules/org.eclipse.persistence.core.jar ../modules/
org.eclipse.persistence.jpa.jar
../modules/org.eclipse.persistence.jp
a.modelgen.jar
../modules/org.eclipse.persistence.oracle.jar ../modul
es/endorsed/javax.annotation.jar
../modules/javax.ejb.jar ../modules/
javax.enterprise.deploy.jar
../modules/javax.jms.jar ../modules/javax
.management.j2ee.jar
../modules/javax.resource.jar ../modules/javax.s
ecurity.auth.message.jar
../modules/javax.security.jacc.jar ../module
s/javax.servlet.jar
../modules/javax.servlet.jsp.jar ../modules/javax
.transaction.jar
../modules/simple-glassfish-api.jar ../modules/admin
-core.jar ../modules/admin-util.jar
../modules/config-api.jar ../modu
les/monitoring-core.jar ../modules/acc-config.jar
../modules/gf-clien
t-module.jar ../modules/gms-bootstrap.jar
../modules/amx-core.jar ../
modules/amx-j2ee.jar
../modules/annotation-framework.jar ../modules/c
ommon-util.jar ../modules/container-common.jar
../modules/glassfish-a
pi.jar ../modules/glassfish-ee-api.jar
../modules/glassfish-naming.ja
r ../modules/internal-api.jar
../modules/scattered-archive-api.jar ..
/modules/stats77.jar
../modules/connectors-inbound-runtime.jar ../mod
ules/connectors-internal-api.jar
../modules/connectors-runtime.jar ..
/modules/work-management.jar
../modules/glassfish.jar ../modules/kern
el.jar ../modules/logging.jar
../modules/deployment-common.jar ../mod
ules/deployment-javaee-core.jar
../modules/dol.jar ../modules/ejb-con
tainer.jar ../modules/ejb-internal-api.jar
../modules/ldapbp-repackag
ed.jar ../modules/libpam4j-repackaged.jar
../modules/management-api.j
ar ../modules/flashlight-agent.jar
../modules/flashlight-framework.ja
r ../modules/gmbal.jar ../modules/ha-api.jar
../modules/class-model.j
ar ../modules/asm-all-repackaged.jar
../modules/bean-validator.jar ..
/modules/jms-core.jar
../modules/endorsed/webservices-api-osgi.jar ..
/modules/webservices-extra-jdk-packages.jar
../modules/webservices-os