Segui o tutorial encontrado aqui no guj.
Link: http://www.guj.com.br/java/222463-solucao-jndi-glassfish---carrinhobean
porém ao gerar o jar na pasta dist, o mesmo não funciona fora do netbeans…
O erro:
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
Como faço para funcionar???
Continua não funcionando…
No meu cliente tenho o codigo:
package br.com.tutorial;
import br.com.teste.HelloBeanRemote;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class EjbCliente {
public static void main(String[] args) {
EjbCliente client = new EjbCliente();
client.connect();
}
public void connect(){
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
/* ? If GlassFish ? */
InitialContext ctx = new InitialContext();
HelloBeanRemote helloRemote = (HelloBeanRemote)ctx.lookup("java:global/AgoraVai/HelloBean");
System.out.println(helloRemote.test());
// Deve ser utilizado a interface e não a implementação.
} catch (NamingException e) {
e.printStackTrace();
}
}
}
No Bean…
package br.com.teste;
import javax.ejb.Stateless;
/**
* Session Bean implementation class HelloBean
*/
@Stateless (name = "HelloBean" , mappedName = "HelloBean")
public class HelloBean implements HelloBeanRemote{
/**
* Default constructor.
*/
public HelloBean() {
// TODO Auto-generated constructor stub
}
public String test() {
return "Remote is Ready";
}
}
package br.com.teste;
import javax.ejb.Remote;
@Remote
public interface HelloBeanRemote {
//JNDI name
static final String JNDI_NAME = "HelloBean#br.com.teste.HelloBeanRemote";
public String test( );
}