title: Cannot access remote EJB interface using JNDI
body: <p>How to remote access a method, or what am I doing wrong? Can you please tell me?:</p>
  
  <pre><code>public class OfferManagerBeanTest {
      private static Context ctx;
  
      @BeforeClass
      public static void initContainer() throws Exception
      {
          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");
          props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
          props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
  
          ctx = new InitialContext(props);
      }
  
      @Test
      public void commitOfferTest() throws NamingException
      {
          OfferManager offerManager = (OfferManager) ctx.lookup("java:global/project/projectEJB/OfferManagerBean");
          assertNotNull(offerManager);    
      }
  }
  </code></pre>
  
  <p>My problem is that I get an error after running this test case.</p>
  
  <p>I get it working but I don't understand why it is working in another case.</p>
  
  <p>Here is my EJB:</p>
  
  <pre><code>@Stateless
  public class OfferManagerBean implements OfferManager, OfferManagerLocal
  </code></pre>
  
  <p>Where <code>OfferManager</code> is a <code>@Remote</code> interface and <code>OfferManagerLocal</code> is a <code>@Local</code> interface.
  If I run this on my WebProject(war file) it is working... (I don't have the properties there)</p>
  
  <p>If I let everything like this and run the jUnit test I get an error like:</p>
  
  <pre><code>javax.naming.NamingException: Lookup failed for 'java:global/project/projectEJB/OfferManagerBean' 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: OfferManagerBean 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 ro.project.ejb.test.OfferManagerBeanTest.commitOfferTest(OfferManagerBeanTest.java:50)
      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 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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      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.NameNotFoundException: OfferManagerBean 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.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)
  </code></pre>
  
  <p>I found something like:</p>
  
  <pre><code>ctx.lookup("java:global/project/projectEJB/OfferManagerBean!ro.project.ejb.interfaces.OfferManager");
  </code></pre>
  
  <p>?? isn't there a better/shorter solution?
  Can anyone tell me why is this happening?</p>
  
  <p>If I let my declaration like: </p>
  
  <pre><code>@Stateless
  public class OfferManagerBean implements OfferManager
  </code></pre>
  
  <p>Everything is working.
  Do you know how can I fix this?</p>