| Prev | Next | J2EETM Developer's Guide
Getting Started |
remote interface follows.
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface Converter extends EJBObject {
public double dollarToYen(double dollars) throws RemoteException;
public double yenToEuro(double yen) throws RemoteException;
}
interface contains a single create method, which returns an object of the remote interface type. Here is the source code for the ConverterHome interface:
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface ConverterHome extends EJBHome {
Converter create() throws RemoteException, CreateException;
}
ConverterEJB. This bean implements the two business methods, dollarToYen and yenToEuro, that the Converter remote interface defines. The source code for the ConverterEJB class follows.
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public class ConverterEJB implements SessionBean {
public double dollarToYen(double dollars) {
return dollars * 121.6000;
}
public double yenToEuro(double yen) {
return yen * 0.0077;
}
public ConverterEJB() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}
}
Converter.java), home interface (ConverterHome.java) , and the enterprise bean class (ConverterEJB.java).
compileEJB.sh, change <installation-location> to the directory in which you installed the J2EE SDK.
2. Run the compileEJB.sh script.#!/bin/sh J2EE_HOME=<installation-location> CPATH=.:$J2EE_HOME/lib/j2ee.jar javac -classpath "$CPATH" ConverterEJB.java ConverterHome.java Converter.java
compileEJB.bat, change <installation-location> to the directory in which you installed the J2EE SDK.
2. Run theset J2EE_HOME=<installation-location> set CPATH=.;%J2EE_HOME%\lib\j2ee.jar javac -classpath %CPATH% ConverterEJB.java ConverterHome.java Converter.java
compileEJB.bat script.