1

I'm testing Remote EJB from a standlone client to a call a jar file deployed in a glassfish server 4, but it show me the following message:

Grave: null
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:307)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at mx.com.gm.sga.cliente.ClientePersonaService.main(ClientePersonaService.java:39)

My code is :

public static void main( String[] args )
{
    System.out.println("------------Calling EJB from a client --------------- ");
    try {
        InitialContext jndi = new InitialContext( );

        PersonaServiceRemote personaService = (PersonaServiceRemote) jndi.lookup( "java:global/sga-jee/PersonaServiceImpl!mx.com.gm.sga.servicio.PersonaServiceRemote" );
        List< Persona > personas = personaService.listarPersonas();
        for (Persona persona : personas) {
            System.out.println( persona );
        }
    } catch (NamingException ex) {
        Logger.getLogger(ClientePersonaService.class.getName()).log(Level.SEVERE, null, ex);
    }

    System.out.println("------------End calling EJB --------------- ");
}
eckes
  • 10,103
  • 1
  • 59
  • 71
Robert
  • 29
  • 2
  • 5

2 Answers2

1

JNDI allows different providers. For the initial context the name of the actual implementation is specified with the system property java.naming.factory.initial. In case of GlassFish according to the FAQ you don't need this. But I think it requires that you add the correct glassfish client library in order to make it work with the default context: $GLASSFISH_HOME/glassfish/lib/gf-client.jar. Check out the FAQ, it lists a few different cases (standalone, app client, second app server, ...).

eckes
  • 10,103
  • 1
  • 59
  • 71
0

the error was for the: JDTA connection in the Persistence Unit. I configure the Persistence Unit as JDTA and I created the pool connection in GlassFish and whole work fine. ;)

Robert
  • 29
  • 2
  • 5