我正在测试从独立客户端到调用部署在 glassfish 服务器 4 中的 jar 文件的远程 EJB,但它向我显示以下消息:
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)
我的代码是:
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 --------------- ");
}