Have been trying to run my first EJB project for a couple of days so far. My EJB project currently has this source code:
package calc;
import javax.ejb.Remote;
@Remote
public interface SessionBeanRemote {
public int add(int a,int b);
}
package calc;
import javax.ejb.Stateless;
@Stateless(name="MySessionBean",mappedName="myCalculator")
public class SessionBean implements SessionBeanRemote {
public int add(int a,int b){
return a +b;
}
}
Secondly, Have another simple java project where I can call EJB component :
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.enterprise.naming.
SerialInitContextFactory");
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ctx = new InitialContext(props);
SessionBeanRemote bean = (SessionBeanRemote) ctx.lookup("myCalculator");
int result = bean.add(3, 4);
System.out.println(result);
ctx.close();
JAR used : gf-client.jar, No need to add other JARs as Glassfish community commended
Exception caught :
java.lang.NoSuchMethodError: com.sun.corba.ee.spi.orbutil.fsm.FSMImpl.(Lcom/sun/corba/ee/spi/orbutil/fsm/StateEngine;Lcom/sun/corba/ee/spi/orbutil/fsm/State;Z)V
2 other questions :
context.lookup("java:global:/componentAddress")
vs context.loopup("mappedName")
what is the difference between them, when to use each ?
props.setProperty("org.omg.CORBA.ORBInitialHost", "192.168.1.100")
vs.
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost")
Simply problem came down to glassfish version 3.0, Downloaded the latest version 3.1.2 and everything works brilliant .