0

I have to implement two simples java projects ; the first is an EJB projectwho contains a simple service which implement a remote interface, and the second project is a java client which try to call this ejb project , so here is what I did until now :

Context context = new InitialContext(jndiProperties);
    TestServiceRemote proxy = (TestServiceRemote) context
            .lookup("java:global/testEJB/TestService!services.TestServiceRemote");
    System.out.println(proxy.showHello());

and this my ejb service :

@Stateless
public class TestService implements TestServiceRemote {

public TestService() {

}

@Override
public String showHello() {
    return "Hello";

}

}

finally this my Remote interface :

@Remote
public interface TestServiceRemote {
   public String showHello();
}

I had deployed the EJB in WIldfly 9 , but when I launch the java client i get this error shown in console :

Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at swing.testClient.main(testClient.java:22)

Can someone tell me what I had wrong in my code ?

majd hwas
  • 95
  • 2
  • 2
  • 10

1 Answers1

0

The java: namespace is not available by default in Java. You can either package your main class as an application client JAR inside an EAR and run it using an application client container launcher, or you can configure the InitialContext to have access to the java: namespace as described in this blog post.

Brett Kail
  • 33,593
  • 2
  • 85
  • 90