EJB in Jboss AS 7.1
ally_535 Jul 17, 2014 8:03 AMHi Guys,
I'm a beginner with Java/EJB. I'm trying to setup a basic session bean program. I went through many online materials and finally made a simple program. I'm getting the following error when i run my client. i'm using jboss 7 and eclipse (kepler)
******************************************
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(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at test.psp.gdc.client.AllyClient.doLookup(AllyClient.java:66)
at test.psp.gdc.client.AllyClient.invokeAlly(AllyClient.java:33)
at test.psp.gdc.client.AllyClient.main(AllyClient.java:24)
*********************************************
My Bean Class is like this
*****************************
package test.psp.gdc.SEB;
import javax.ejb.Remote;
import javax.ejb.Stateless;
/**
* Session Bean implementation class Ally
*/
@Stateless
@Remote(AllyRemote.class)
public class Ally implements AllyRemote {
public Ally() {
// TODO Auto-generated constructor stub
}
public String callAlly(){
return "Alucard";
}
}
Remote Interface:
********************
package test.psp.gdc.SEB;
import javax.ejb.Remote;
@Remote
public interface AllyRemote {
public String callAlly();
}
Client:
*******
package test.psp.gdc.client;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import test.psp.gdc.SEB.Ally;
import test.psp.gdc.SEB.AllyRemote;
public class AllyClient {
public static void main(String[] args) throws Exception {
invokeAlly();
}
private static void invokeAlly() throws NamingException {
// TODO Auto-generated method stub
final AllyRemote nats = doLookup();
System.out.println("Calling the Session Bean");
System.out.println("Bean Output:" +nats.callAlly());
}
private static AllyRemote doLookup() throws NamingException{
// TODO Auto-generated method stub
final Hashtable jp = new Hashtable();
jp.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
Context context = new InitialContext(jp);
//App Name
final String appName="";
//Module Name
final String modName="Lightning";
//Distinct Name
final String disName="";
//EJB Name
final String ejbName=Ally.class.getSimpleName();
//view Class Name
final String viewClassName=AllyRemote.class.getName();
return (AllyRemote) context.lookup("ejb:" + appName + "/" + modName + "/" + disName + "/" + ejbName + "/" + viewClassName);
}
}
************************************
jboss-ejb-client.properties
*****************************
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=Nats
remote.connection.default.password=ally