Cant access EJB from a Java SE client - Lookup Failed Error

匿名 (未验证) 提交于 2019-12-03 08:56:10

问题:

I am using Netbeans and am experimenting with EJBs.

I have two projects (2 separate applications)

1- A Java ME Project called EnterpriseApp

2- A standard Java SE Project called Test

Now here is what I did - in EnterpriseApp I generated a stateless EJB called TestEJB with both local and remote interfaces. For the remote project selection I selected the Test App. In short the bean code looks like this

@Stateless public class TestEjb implements TestEjbRemote, TestEjbLocal  {     @Override     public String Try()      {         return "Hello World";     }  }

And in the Java SE client Project here is my main class through which I am trying to access the bean:

public class Main  {     public static void main(String[] args)      {         try          {                 Properties props = new Properties();                 props.load(new FileInputStream("jndi.properties"));                 InitialContext ctx = new InitialContext(props);                 TestEjbRemote testEJB = (TestEjbRemote) ctx.lookup("stateless.TestEjbRemote");                 System.out.println(testEJB.Try());         }          catch (NamingException nex)          {                 nex.printStackTrace();         }          catch (FileNotFoundException fnfex)          {                 fnfex.printStackTrace();         }          catch (IOException ioex)          {                 ioex.printStackTrace();         }     }   }

This is the contents of JNDI.properties file

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 #optional.  Defaults to localhost.  Only needed if web server is running #on a different host than the appserver org.omg.CORBA.ORBInitialHost = localhost #optional.  Defaults to 3700.  Only needed if target orb port is not 3700. org.omg.CORBA.ORBInitialPort = 3700

And I get this error at

 TestEjbRemote testEJB = (TestEjbRemote) ctx.lookup("stateless.TestEjbRemote");  javax.naming.NamingException: Lookup failed for 'stateless.TestEjbRemote' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, 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.NameNotFoundException: stateless.TestEjbRemote 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:392)     at Main.main(Main.java:19) Caused by: javax.naming.NameNotFoundException: stateless.TestEjbRemote 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.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)     at com.sun.enterprise.naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:109)     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 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)

Any suggestions on how I may resolve this issue ?

回答1:

conceptually you did everything right. So this should be some 'wrong-name' related issue.

Good news that you can check it :)

EJB once got recognized by the application server is deployed. This means that the stubs are created and put by the AS into the JNDI tree. This means that once the server is started, you can go to JNDI tree viewer (usually its supplied with the aplpication server) and see what's got deployed where. I believe, given you've set up your jars properly this should work.

Hope this helps



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!