本文介绍了EJB 3.1 |通过JNDI调用远程会话bean时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的bean p>

  import javax.ejb.Stateless; 

/ **
*
* @author MMRUser
* /
@Stateless
public class CapitalBean implements CapitalBeanRemote {

public String greetingsEjb(String name){
returnHello+ name;
}
}

远程接口 p>

  import javax.ejb.Remote; 

/ **
*
* @author MMRUser
* /
@Remote
public interface CapitalBeanRemote {

public String greetingsEjb(String name);
}

从我的客户端我使用独立的java类调用会话bean使用JNDI如下

  import ejb.CapitalBeanRemote; 
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/ **
*
* @author MMRUser
* /
public class CallEjbClass {

public static void main (String [] args){
try {
Context context = new InitialContext();
CapitalBeanRemote bean =(CapitalBeanRemote)
context.lookup(java:global / CapitalApplication / CapitalBean);
context.close();
} catch(NamingException ex){
ex.printStackTrace();
}


}
}



  avax.naming.NameNotFoundException没有找到CapitalBean 

我使用Glassfish 3.1.1作为我的应用服务器和Netbeans 7.0.1作为我的IDE已经将这些jar文件添加到我的类路径中:



CapitalApplication-ejb.jar



appserv-rt.jar



gf-client.jar



我也尝试过不同的JNDI命名约定,如:



java:global / CapitalApplication!ejb.CapitalBean



这是完整的堆栈跟踪

 运行:
2011年11月20日下午6:14:58 com.sun.enterprise.iiop.security.SecurityMechanismSelector postConstruct
SEVERE:IIOP1005:ejb安全初始化中发生异常。
org.jvnet.hk2.component.ComponentException:注册失败在org.glassfish.api.invocation.InvocationManagerImpl.invHandlers与类[Lorg.glassfish.api.invocation.ComponentInvocationHandler;
在org.jvnet.hk2.component.InjectionManager.error_injectionException(InjectionManager.java:277)
在org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:159)
在org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:91)
在com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:126)
在com.sun .hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
在com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
在com.sun.hk2.component .SingletonInhabitant.get(SingletonInhabitant.java:67)
在com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
在com.sun.hk2.component.AbstractInhabitantImpl.get (AbstractInhabitantImpl.java:76)
在org.jvnet.hk2.component.Habitat.getByContract(Habitat.java:1042)
在org.jvnet.hk2.component.Habitat.getComponent(Habitat.java :777)
在com.sun。 com.un.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:131)中的
在com.sun.hk2中的
enterprise.iiop.security.SecurityMechanismSelector.postConstruct(SecurityMechanismSelector.java:166)
。 com.un.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)上的
(comstructorCreator.java:91)com.un.hk2.component.SingletonInhabitant中的
。 get(SingletonInhabitant.java:67)
在com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
在com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl。 java:76)
在org.jvnet.hk2.component.Habitat.getBy(Habitat.java:1048)
在org.jvnet.hk2.component.Habitat.getByType(Habitat.java:1029)
在com.sun.hk2.component.InjectInjectionResolver.getComponentInjectValue(InjectInjectionResolver.java:159)
在com.sun.hk2.component.InjectInjectionResolver.getValue(InjectInjectionResolver。 java:90)
在org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:141)
在org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:91)
在com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:126)
在com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
在com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
在com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
在com.sun .hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
在com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
在org.jvnet.hk2.component .Habitat.getBy(Habitat.java:1048)
在org.jvnet.hk2.component.Habitat.getByType(Habitat.java:1029)
在org.jvnet.hk2.component.Habitat.getComponent (Habitat.java:779)
在com.sun.enterprise.iiop.security.Lookup s._getSecurityContextUtil(Lookups.java:97)
在com.sun.enterprise.iiop.security.Lookups.getSecurityContextUtil(Lookups.java:92)
在com.sun.enterprise.iiop.security。 SecClientRequestInterceptor。< init>(SecClientRequestInterceptor.java:119)
在com.sun.enterprise.security.appclient.AppclientIIOPInterceptorFactory.getClientInterceptorInstance(AppclientIIOPInterceptorFactory.java:127)
在com.sun.enterprise.security .appclient.AppclientIIOPInterceptorFactory.createClientRequestInterceptor(AppclientIIOPInterceptorFactory.java:96)
在org.glassfish.enterprise.iiop.impl.GlassFishORBInitializer.post_init(GlassFishORBInitializer.java:132)
在com.sun.corba.ee .impl.interceptors.PIHandlerImpl.postInitORBInitializers(PIHandlerImpl.java:915)
在com.sun.corba.ee.impl.interceptors.PIHandlerImpl.initialize(PIHandlerImpl.java:265)
在com.sun .corba.ee.impl.orb.ORBImpl.postInit(ORBImpl.java:643)
在com.sun.corba.ee.impl.orb.OR BImpl.set_parameters(ORBImpl.java:704)
在com.sun.corba.ee.impl.orb.ORBImpl.setParameters(ORBImpl.java:691)
在com.sun.corba.ee。 spi.osgi.ORBFactory.initialize(ORBFactory.java:107)
在org.glassfish.enterprise.iiop.impl.GlassFishORBManager.initORB(GlassFishORBManager.java:581)
在org.glassfish.enterprise。 iOp.impl.GlassFishORBManager.getORB(GlassFishORBManager.java:263)
在org.glassfish.enterprise.iiop.impl.GlassFishORBFactoryImpl.createORB(GlassFishORBFactoryImpl.java:93)
在org.glassfish.enterprise。 com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
com.sun.enterprise中的
(GlassFishORBHelper.java:152) com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
com.sun.enterprise上的
(串行连接文件) naming.impl.SerialContext.getProvider(SerialContext.java:34 7)
在com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
在com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java: 455)
在javax.naming.InitialContext.lookup(InitialContext.java:411)
在firstjavaapp.CallEjbClass.main(CallEjbClass.java:21)
导致:org.jvnet.hk2 .component.ComponentException:在com.sun.hk2.component.ConstructorCreator.create(ConstructorCreator.java:71)$ com创建类com.sun.enterprise.resource.pool.PoolManagerImpl
。 sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:80)
在com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
在com.sun.hk2。 component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
在com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
在org.jvnet.hk2.component.Habitat $ 5 .get(Habitat.java:701)
在java.util.Abstrac tList $ Itr.next(AbstractList.java:358)
在java.util.AbstractCollection.toArray(AbstractCollection.java:188)
在com.sun.hk2.component.InjectInjectionResolver.getArrayInjectValue(InjectInjectionResolver。 java:113)
在com.sun.hk2.component.InjectInjectionResolver.getValue(InjectInjectionResolver.java:81)
在org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:141)
... 55更多
导致:java.lang.ClassFormatError:在java.lang中的类文件javax / resource / ResourceException
中的本地或抽象方法中的Absent Code属性。 ClassBoader.defineClass1 java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
在java.net.URLClassLoader.access $ 100(URLClassLoader.java:71)
在java.net.URLClassLoader $ 1.run(URLClassLo ader.java:361)
在java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)
在java.security.AccessController.doPrivileged(本机方法)
在java.net .URLClassLoader.findClass(URLClassLoader.java:354)
在java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308 )
在java.lang.ClassLoader.loadClass(ClassLoader.java:356)
在java.lang.Class.getDeclaredConstructors0(本机方法)
在java.lang.Class.privateGetDeclaredConstructors(类.java:2404)
在java.lang.Class.getConstructor0(Class.java:2714)
在java.lang.Class.newInstance0(Class.java:343)
在java。 lang.Class.newInstance(Class.java:325)
在com.sun.hk2.component.ConstructorCreator.create(ConstructorCreator.java:65)
... 65更多

javax.naming.NamingException:SerialContext中的java:global / CapitalApplication / CapitalBean查找失败[myEnv = {java.naming .factory.initial = com.sun.enterprise.naming.impl.SerialInitContextFactory,java.naming.factory.url.pkgs = com.sun.enterprise.naming,java.naming.factory.state = com.sun.corba.ee .impl.presentation.rmi.JNDIStateFactoryImpl} [根异常是javax.naming.NameNotFoundException:未找到CapitalBean]
在com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
在javax.naming.InitialContext.lookup(InitialContext.java:411)
at firstjavaapp.CallEjbClass .main(CallEjbClass.java:21)
导致:javax.naming.NameNotFoundException:没有找到CapitalBean $ com
com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:248)
在com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:215)
在com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:219) com.sun.enterprise.nam上的
ing.impl.TransientContext.lookup(TransientContext.java:219)
在com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
在com.sun.enterprise。 naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在java.lang.reflect.Method.invoke(Method.java:601)
在com.sun.corba。 ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:144)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:174)
在com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:528)
在com.sun.corba.ee.impl.protocol.Co在com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1624)
在com.sun.corba.ee上的
(rbaServerRequestDispatcherImpl.java:199) com.un.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:990)
在com.sun中。 corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:214)
在com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:742)
在com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:539)
在com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2324 )
在com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl $ WorkerThread.performWork(ThreadPoolI mpl.java:497)
在com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl $ WorkerThread.run(ThreadPoolImpl.java:540)
BUILD SUCCESSFUL(总时间:3秒)

更新



尝试将JNDI命名约定更改为:

  java:global / CapitalApplication / CapitalApplication-ejb / CapitalBean!ejb.CapitalBeanRemote 

现在我收到一个不同的例外:

 运行:
2011年11月20日下午7:08:52 com.sun.enterprise.iiop.security.SecurityMechanismSelector postConstruct
SEVERE:IIOP1005:An在ejb安全初始化中发生异常。
org.jvnet.hk2.component.ComponentException:注册失败在org.glassfish.api.invocation.InvocationManagerImpl.invHandlers与类[Lorg.glassfish.api.invocation.ComponentInvocationHandler;
在org.jvnet.hk2.component.InjectionManager.error_injectionException(InjectionManager.java:277)
在org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:159)
在org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:91)
在com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:126)
在com.sun .hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
在com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
在com.sun.hk2.component .SingletonInhabitant.get(SingletonInhabitant.java:67)
在com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
在com.sun.hk2.component.AbstractInhabitantImpl.get (AbstractInhabitantImpl.java:76)
在org.jvnet.hk2.component.Habitat.getByContract(Habitat.java:1042)
在org.jvnet.hk2.component.Habitat.getComponent(Habitat.java :777)
在com.sun。 com.un.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:131)中的
在com.sun.hk2中的
enterprise.iiop.security.SecurityMechanismSelector.postConstruct(SecurityMechanismSelector.java:166)
。 com.un.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)上的
(comstructorCreator.java:91)com.un.hk2.component.SingletonInhabitant中的
。 get(SingletonInhabitant.java:67)
在com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
在com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl。 java:76)
在org.jvnet.hk2.component.Habitat.getBy(Habitat.java:1048)
在org.jvnet.hk2.component.Habitat.getByType(Habitat.java:1029)
在com.sun.hk2.component.InjectInjectionResolver.getComponentInjectValue(InjectInjectionResolver.java:159)
在com.sun.hk2.component.InjectInjectionResolver.getValue(InjectInjectionResolver。 java:90)
在org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:141)
在org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:91)
在com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:126)
在com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
在com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
在com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
在com.sun .hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
在com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
在org.jvnet.hk2.component .Habitat.getBy(Habitat.java:1048)
在org.jvnet.hk2.component.Habitat.getByType(Habitat.java:1029)
在org.jvnet.hk2.component.Habitat.getComponent (Habitat.java:779)
在com.sun.enterprise.iiop.security.Lookup s._getSecurityContextUtil(Lookups.java:97)
在com.sun.enterprise.iiop.security.Lookups.getSecurityContextUtil(Lookups.java:92)
在com.sun.enterprise.iiop.security。 SecClientRequestInterceptor。< init>(SecClientRequestInterceptor.java:119)
在com.sun.enterprise.security.appclient.AppclientIIOPInterceptorFactory.getClientInterceptorInstance(AppclientIIOPInterceptorFactory.java:127)
在com.sun.enterprise.security .appclient.AppclientIIOPInterceptorFactory.createClientRequestInterceptor(AppclientIIOPInterceptorFactory.java:96)
在org.glassfish.enterprise.iiop.impl.GlassFishORBInitializer.post_init(GlassFishORBInitializer.java:132)
在com.sun.corba.ee .impl.interceptors.PIHandlerImpl.postInitORBInitializers(PIHandlerImpl.java:915)
在com.sun.corba.ee.impl.interceptors.PIHandlerImpl.initialize(PIHandlerImpl.java:265)
在com.sun .corba.ee.impl.orb.ORBImpl.postInit(ORBImpl.java:643)
在com.sun.corba.ee.impl.orb.OR BImpl.set_parameters(ORBImpl.java:704)
在com.sun.corba.ee.impl.orb.ORBImpl.setParameters(ORBImpl.java:691)
在com.sun.corba.ee。 spi.osgi.ORBFactory.initialize(ORBFactory.java:107)
在org.glassfish.enterprise.iiop.impl.GlassFishORBManager.initORB(GlassFishORBManager.java:581)
在org.glassfish.enterprise。 iOp.impl.GlassFishORBManager.getORB(GlassFishORBManager.java:263)
在org.glassfish.enterprise.iiop.impl.GlassFishORBFactoryImpl.createORB(GlassFishORBFactoryImpl.java:93)
在org.glassfish.enterprise。 com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
com.sun.enterprise中的
(GlassFishORBHelper.java:152) com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
com.sun.enterprise上的
(串行连接文件) naming.impl.SerialContext.getProvider(SerialContext.java:34 7)
在com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
在com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java: 455)
在javax.naming.InitialContext.lookup(InitialContext.java:411)
在firstjavaapp.CallEjbClass.main(CallEjbClass.java:20)
导致:org.jvnet.hk2 .component.ComponentException:在com.sun.hk2.component.ConstructorCreator.create(ConstructorCreator.java:71)$ com创建类com.sun.enterprise.resource.pool.PoolManagerImpl
。 sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:80)
在com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
在com.sun.hk2。 component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
在com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
在org.jvnet.hk2.component.Habitat $ 5 .get(Habitat.java:701)
在java.util.Abstrac tList $ Itr.next(AbstractList.java:358)
在java.util.AbstractCollection.toArray(AbstractCollection.java:188)
在com.sun.hk2.component.InjectInjectionResolver.getArrayInjectValue(InjectInjectionResolver。 java:113)
在com.sun.hk2.component.InjectInjectionResolver.getValue(InjectInjectionResolver.java:81)
在org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:141)
... 55更多
导致:java.lang.ClassFormatError:在java.lang中的类文件javax / resource / ResourceException
中的本地或抽象方法中的Absent Code属性。 ClassBoader.defineClass1 java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
在java.net.URLClassLoader.access $ 100(URLClassLoader.java:71)
在java.net.URLClassLoader $ 1.run(URLClassLo ader.java:361)
在java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)
在java.security.AccessController.doPrivileged(本机方法)
在java.net .URLClassLoader.findClass(URLClassLoader.java:354)
在java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308 )
在java.lang.ClassLoader.loadClass(ClassLoader.java:356)
在java.lang.Class.getDeclaredConstructors0(本机方法)
在java.lang.Class.privateGetDeclaredConstructors(类.java:2404)
在java.lang.Class.getConstructor0(Class.java:2714)
在java.lang.Class.newInstance0(Class.java:343)
在java。 lang.Class.newInstance(Class.java:325)
在com.sun.hk2.component.ConstructorCreator.create(ConstructorCreator.java:65)
... 65更多

线程main中的异常java.lang.ClassFormatError:方法中的Absent Code属性不是本地或抽象的类文件java.lang.ClassLoader.defineClass1(Native Method)中的javax / ejb / RemoveException

java.lang.ClassLoader.defineClass(ClassLoader.java:791)
在java.security.SecureClassLoader .defineClass(SecureClassLoader.java:142)
在java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
在java.net.URLClassLoader.access $ 100(URLClassLoader.java:71)
在java.net.URLClassLoader $ 1.run(URLClassLoader.java:361)
在java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)
在java.security.AccessController.doPrivileged (Native Method)
在java.net.URLClassLoader.findClass(URLClassLoader.java:354)
在java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc .Launcher $ AppClassLoader.loadClass(Launcher.java:308)
在java.lang.ClassLoader.loadClass(ClassLoader.java:356)
在java.lang.Class.getDeclaredMethods0(本机方法)
在java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
在java.lang.Class.privateGetPublicMethods(Class.java:2562)
在java.lang.Class.privateGetPublicMethods(Class.java:2572)
在java.lang.Class.privateGetPublicMethods (Class.java:2572)
在java.lang.Class.getMethods(Class.java:1427)
在com.sun.corba.ee.impl.presentation.rmi.IDLTypesUtil.validateRemoteInterface(IDLTypesUtil .java:96)
at com.sun.corba.ee.impl.presentation.rmi.IDLNameTranslatorImpl。< init>(IDLNameTranslatorImpl.java:226)
at com.sun.corba.ee。 (p。int) b $ b在com.sun.corba.ee.impl.presentation.rmi.IDLNameTranslatorImpl $ 2.run(IDLNameTranslatorImpl.java:167)
在java.security.AccessController.doPrivileged(本机方法)
在com.sun.corba.ee.impl.presentation.rmi.IDLNameTranslatorImpl.get(IDLNameTranslatorImpl。 java:166)
at com.sun.corba.ee.impl.presentation.rmi.PresentationManagerImpl $ ClassDataImpl。< init>(PresentationManagerImpl.java:153)
at com.sun.corba.ee .impl.presentation.rmi.PresentationManagerImpl $ 1.lookup(PresentationManagerImpl.java:103)
在com.sun.corba.ee.impl.presentation.rmi.PresentationManagerImpl $ 1.lookup(PresentationManagerImpl.java:100)
at com.sun.corba.ee.spi.orbutil.misc.WeakCache.get(WeakCache.java:114)
at com.sun.corba.ee.impl.presentation.rmi.PresentationManagerImpl.getClassData( PresentationManagerImpl.java:131)
在com.sun.corba.ee.impl.presentation.rmi.StubFactoryFactoryDynamicBase.createStubFactory(StubFactoryFactoryDynamicBase.java:91)
在com.sun.corba.ee.impl。 util.Utility.loadStub(Utility.java:835)
在com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:252)
在javax.rmi。 PortableRemoteObject.narrow(PortableRemoteObject.java:153)
在com.sun。 ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:406)
在com.sun.ejb.containers.RemoteBusinessObjectFactory.getObjectInstance(RemoteBusinessObjectFactory.java:75)
在javax.naming.spi.NamingManager.getObjectInstance( NamingManager.java:321)
在com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:556)
在com.sun.enterprise.naming.impl.SerialContext.lookup( SerialContext.java:514)
在com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
在javax.naming.InitialContext.lookup(InitialContext.java:411)
at firstjavaapp.CallEjbClass.main(CallEjbClass.java:20)
Java结果:1
BUILD SUCCESSFUL(总时间:3秒)
/ pre>

解决方案

我有同样的问题,只是发现了。



ST。关键是类路径中JAR文件的顺序。确保在javaee-api-6.0.jar之前包含gf-client.jar。


I'm trying to call a simple stateless session bean from a Java SE (Simple class).

Here's my bean

import javax.ejb.Stateless;

/**
 *
 * @author MMRUser
 */
@Stateless
public class CapitalBean implements CapitalBeanRemote {

    public String greetingsEjb(String name) {
        return "Hello " + name;
    }
}

Remote interface

import javax.ejb.Remote;

/**
 *
 * @author MMRUser
 */
@Remote
public interface CapitalBeanRemote {

    public String greetingsEjb(String name);
}

From my client side I used stand-alone java class to call the session bean using JNDI as follows

import ejb.CapitalBeanRemote;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author MMRUser
 */
public class CallEjbClass {

    public static void main(String[] args) {
        try {
            Context context = new InitialContext();
            CapitalBeanRemote bean = (CapitalBeanRemote)
            context.lookup("java:global/CapitalApplication/CapitalBean");
            context.close();
        } catch (NamingException ex) {
            ex.printStackTrace();
        }


    }
}

Things are pretty straight forward, but when I ran this application I'm getting an exception saying

avax.naming.NameNotFoundException: CapitalBean not found

I'm using Glassfish 3.1.1 as my application server and Netbeans 7.0.1 as my IDE. Already added these jar files to my classpath:

CapitalApplication-ejb.jar

appserv-rt.jar

gf-client.jar

I also tried different JNDI naming conventions like:

java:global/CapitalApplication!ejb.CapitalBean

but nothing seems to work here.

Here's the full stack trace

run:
Nov 20, 2011 6:14:58 PM com.sun.enterprise.iiop.security.SecurityMechanismSelector postConstruct
SEVERE: IIOP1005: An exception has occured in the ejb security initialization.
org.jvnet.hk2.component.ComponentException: injection failed on org.glassfish.api.invocation.InvocationManagerImpl.invHandlers with class [Lorg.glassfish.api.invocation.ComponentInvocationHandler;
    at org.jvnet.hk2.component.InjectionManager.error_injectionException(InjectionManager.java:277)
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:159)
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:91)
    at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:126)
    at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
    at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
    at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
    at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
    at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
    at org.jvnet.hk2.component.Habitat.getByContract(Habitat.java:1042)
    at org.jvnet.hk2.component.Habitat.getComponent(Habitat.java:777)
    at com.sun.enterprise.iiop.security.SecurityMechanismSelector.postConstruct(SecurityMechanismSelector.java:166)
    at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:131)
    at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
    at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
    at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
    at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
    at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
    at org.jvnet.hk2.component.Habitat.getBy(Habitat.java:1048)
    at org.jvnet.hk2.component.Habitat.getByType(Habitat.java:1029)
    at com.sun.hk2.component.InjectInjectionResolver.getComponentInjectValue(InjectInjectionResolver.java:159)
    at com.sun.hk2.component.InjectInjectionResolver.getValue(InjectInjectionResolver.java:90)
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:141)
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:91)
    at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:126)
    at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
    at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
    at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
    at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
    at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
    at org.jvnet.hk2.component.Habitat.getBy(Habitat.java:1048)
    at org.jvnet.hk2.component.Habitat.getByType(Habitat.java:1029)
    at org.jvnet.hk2.component.Habitat.getComponent(Habitat.java:779)
    at com.sun.enterprise.iiop.security.Lookups._getSecurityContextUtil(Lookups.java:97)
    at com.sun.enterprise.iiop.security.Lookups.getSecurityContextUtil(Lookups.java:92)
    at com.sun.enterprise.iiop.security.SecClientRequestInterceptor.<init>(SecClientRequestInterceptor.java:119)
    at com.sun.enterprise.security.appclient.AppclientIIOPInterceptorFactory.getClientInterceptorInstance(AppclientIIOPInterceptorFactory.java:127)
    at com.sun.enterprise.security.appclient.AppclientIIOPInterceptorFactory.createClientRequestInterceptor(AppclientIIOPInterceptorFactory.java:96)
    at org.glassfish.enterprise.iiop.impl.GlassFishORBInitializer.post_init(GlassFishORBInitializer.java:132)
    at com.sun.corba.ee.impl.interceptors.PIHandlerImpl.postInitORBInitializers(PIHandlerImpl.java:915)
    at com.sun.corba.ee.impl.interceptors.PIHandlerImpl.initialize(PIHandlerImpl.java:265)
    at com.sun.corba.ee.impl.orb.ORBImpl.postInit(ORBImpl.java:643)
    at com.sun.corba.ee.impl.orb.ORBImpl.set_parameters(ORBImpl.java:704)
    at com.sun.corba.ee.impl.orb.ORBImpl.setParameters(ORBImpl.java:691)
    at com.sun.corba.ee.spi.osgi.ORBFactory.initialize(ORBFactory.java:107)
    at org.glassfish.enterprise.iiop.impl.GlassFishORBManager.initORB(GlassFishORBManager.java:581)
    at org.glassfish.enterprise.iiop.impl.GlassFishORBManager.getORB(GlassFishORBManager.java:263)
    at org.glassfish.enterprise.iiop.impl.GlassFishORBFactoryImpl.createORB(GlassFishORBFactoryImpl.java:93)
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:152)
    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:411)
    at firstjavaapp.CallEjbClass.main(CallEjbClass.java:21)
Caused by: org.jvnet.hk2.component.ComponentException: Failed to create class com.sun.enterprise.resource.pool.PoolManagerImpl
    at com.sun.hk2.component.ConstructorCreator.create(ConstructorCreator.java:71)
    at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:80)
    at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
    at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
    at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
    at org.jvnet.hk2.component.Habitat$5.get(Habitat.java:701)
    at java.util.AbstractList$Itr.next(AbstractList.java:358)
    at java.util.AbstractCollection.toArray(AbstractCollection.java:188)
    at com.sun.hk2.component.InjectInjectionResolver.getArrayInjectValue(InjectInjectionResolver.java:113)
    at com.sun.hk2.component.InjectInjectionResolver.getValue(InjectInjectionResolver.java:81)
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:141)
    ... 55 more
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/resource/ResourceException
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2404)
    at java.lang.Class.getConstructor0(Class.java:2714)
    at java.lang.Class.newInstance0(Class.java:343)
    at java.lang.Class.newInstance(Class.java:325)
    at com.sun.hk2.component.ConstructorCreator.create(ConstructorCreator.java:65)
    ... 65 more

javax.naming.NamingException: Lookup failed for 'java:global/CapitalApplication/CapitalBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.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.NameNotFoundException: CapitalBean not found]
    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:411)
    at firstjavaapp.CallEjbClass.main(CallEjbClass.java:21)
Caused by: javax.naming.NameNotFoundException: CapitalBean not found
    at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:248)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:215)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:219)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:219)
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
    at com.sun.enterprise.naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:94)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:144)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:174)
    at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:528)
    at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:199)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1624)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1486)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:990)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:214)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:742)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:539)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2324)
    at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
BUILD SUCCESSFUL (total time: 3 seconds)

UPDATE

Tried changing the JNDI naming convention to this:

java:global/CapitalApplication/CapitalApplication-ejb/CapitalBean!ejb.CapitalBeanRemote

and now I'm getting a different exception:

run:
Nov 20, 2011 7:08:52 PM com.sun.enterprise.iiop.security.SecurityMechanismSelector postConstruct
SEVERE: IIOP1005: An exception has occured in the ejb security initialization.
org.jvnet.hk2.component.ComponentException: injection failed on org.glassfish.api.invocation.InvocationManagerImpl.invHandlers with class [Lorg.glassfish.api.invocation.ComponentInvocationHandler;
    at org.jvnet.hk2.component.InjectionManager.error_injectionException(InjectionManager.java:277)
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:159)
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:91)
    at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:126)
    at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
    at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
    at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
    at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
    at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
    at org.jvnet.hk2.component.Habitat.getByContract(Habitat.java:1042)
    at org.jvnet.hk2.component.Habitat.getComponent(Habitat.java:777)
    at com.sun.enterprise.iiop.security.SecurityMechanismSelector.postConstruct(SecurityMechanismSelector.java:166)
    at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:131)
    at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
    at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
    at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
    at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
    at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
    at org.jvnet.hk2.component.Habitat.getBy(Habitat.java:1048)
    at org.jvnet.hk2.component.Habitat.getByType(Habitat.java:1029)
    at com.sun.hk2.component.InjectInjectionResolver.getComponentInjectValue(InjectInjectionResolver.java:159)
    at com.sun.hk2.component.InjectInjectionResolver.getValue(InjectInjectionResolver.java:90)
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:141)
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:91)
    at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:126)
    at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
    at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
    at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
    at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
    at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
    at org.jvnet.hk2.component.Habitat.getBy(Habitat.java:1048)
    at org.jvnet.hk2.component.Habitat.getByType(Habitat.java:1029)
    at org.jvnet.hk2.component.Habitat.getComponent(Habitat.java:779)
    at com.sun.enterprise.iiop.security.Lookups._getSecurityContextUtil(Lookups.java:97)
    at com.sun.enterprise.iiop.security.Lookups.getSecurityContextUtil(Lookups.java:92)
    at com.sun.enterprise.iiop.security.SecClientRequestInterceptor.<init>(SecClientRequestInterceptor.java:119)
    at com.sun.enterprise.security.appclient.AppclientIIOPInterceptorFactory.getClientInterceptorInstance(AppclientIIOPInterceptorFactory.java:127)
    at com.sun.enterprise.security.appclient.AppclientIIOPInterceptorFactory.createClientRequestInterceptor(AppclientIIOPInterceptorFactory.java:96)
    at org.glassfish.enterprise.iiop.impl.GlassFishORBInitializer.post_init(GlassFishORBInitializer.java:132)
    at com.sun.corba.ee.impl.interceptors.PIHandlerImpl.postInitORBInitializers(PIHandlerImpl.java:915)
    at com.sun.corba.ee.impl.interceptors.PIHandlerImpl.initialize(PIHandlerImpl.java:265)
    at com.sun.corba.ee.impl.orb.ORBImpl.postInit(ORBImpl.java:643)
    at com.sun.corba.ee.impl.orb.ORBImpl.set_parameters(ORBImpl.java:704)
    at com.sun.corba.ee.impl.orb.ORBImpl.setParameters(ORBImpl.java:691)
    at com.sun.corba.ee.spi.osgi.ORBFactory.initialize(ORBFactory.java:107)
    at org.glassfish.enterprise.iiop.impl.GlassFishORBManager.initORB(GlassFishORBManager.java:581)
    at org.glassfish.enterprise.iiop.impl.GlassFishORBManager.getORB(GlassFishORBManager.java:263)
    at org.glassfish.enterprise.iiop.impl.GlassFishORBFactoryImpl.createORB(GlassFishORBFactoryImpl.java:93)
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:152)
    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:411)
    at firstjavaapp.CallEjbClass.main(CallEjbClass.java:20)
Caused by: org.jvnet.hk2.component.ComponentException: Failed to create class com.sun.enterprise.resource.pool.PoolManagerImpl
    at com.sun.hk2.component.ConstructorCreator.create(ConstructorCreator.java:71)
    at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:80)
    at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
    at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
    at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
    at org.jvnet.hk2.component.Habitat$5.get(Habitat.java:701)
    at java.util.AbstractList$Itr.next(AbstractList.java:358)
    at java.util.AbstractCollection.toArray(AbstractCollection.java:188)
    at com.sun.hk2.component.InjectInjectionResolver.getArrayInjectValue(InjectInjectionResolver.java:113)
    at com.sun.hk2.component.InjectInjectionResolver.getValue(InjectInjectionResolver.java:81)
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:141)
    ... 55 more
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/resource/ResourceException
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2404)
    at java.lang.Class.getConstructor0(Class.java:2714)
    at java.lang.Class.newInstance0(Class.java:343)
    at java.lang.Class.newInstance(Class.java:325)
    at com.sun.hk2.component.ConstructorCreator.create(ConstructorCreator.java:65)
    ... 65 more

Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ejb/RemoveException
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
    at java.lang.Class.privateGetPublicMethods(Class.java:2562)
    at java.lang.Class.privateGetPublicMethods(Class.java:2572)
    at java.lang.Class.privateGetPublicMethods(Class.java:2572)
    at java.lang.Class.getMethods(Class.java:1427)
    at com.sun.corba.ee.impl.presentation.rmi.IDLTypesUtil.validateRemoteInterface(IDLTypesUtil.java:96)
    at com.sun.corba.ee.impl.presentation.rmi.IDLNameTranslatorImpl.<init>(IDLNameTranslatorImpl.java:226)
    at com.sun.corba.ee.impl.presentation.rmi.IDLNameTranslatorImpl.<init>(IDLNameTranslatorImpl.java:65)
    at com.sun.corba.ee.impl.presentation.rmi.IDLNameTranslatorImpl$2.run(IDLNameTranslatorImpl.java:169)
    at com.sun.corba.ee.impl.presentation.rmi.IDLNameTranslatorImpl$2.run(IDLNameTranslatorImpl.java:167)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.corba.ee.impl.presentation.rmi.IDLNameTranslatorImpl.get(IDLNameTranslatorImpl.java:166)
    at com.sun.corba.ee.impl.presentation.rmi.PresentationManagerImpl$ClassDataImpl.<init>(PresentationManagerImpl.java:153)
    at com.sun.corba.ee.impl.presentation.rmi.PresentationManagerImpl$1.lookup(PresentationManagerImpl.java:103)
    at com.sun.corba.ee.impl.presentation.rmi.PresentationManagerImpl$1.lookup(PresentationManagerImpl.java:100)
    at com.sun.corba.ee.spi.orbutil.misc.WeakCache.get(WeakCache.java:114)
    at com.sun.corba.ee.impl.presentation.rmi.PresentationManagerImpl.getClassData(PresentationManagerImpl.java:131)
    at com.sun.corba.ee.impl.presentation.rmi.StubFactoryFactoryDynamicBase.createStubFactory(StubFactoryFactoryDynamicBase.java:91)
    at com.sun.corba.ee.impl.util.Utility.loadStub(Utility.java:835)
    at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:252)
    at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:153)
    at com.sun.ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:406)
    at com.sun.ejb.containers.RemoteBusinessObjectFactory.getObjectInstance(RemoteBusinessObjectFactory.java:75)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
    at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:556)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:514)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at firstjavaapp.CallEjbClass.main(CallEjbClass.java:20)
Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)
解决方案

I had the same problem and just found the solution here.

Check the final post. It seems that the key is the order of the JAR files in the classpath. Make sure you include gf-client.jar before javaee-api-6.0.jar.

这篇关于EJB 3.1 |通过JNDI调用远程会话bean时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 23:33