<?XML:namespace prefix = o ns = "urn:schemas-microsoft-com:Office:office" />
1。所先下載J2SDKEE1.3和J2SDK1.4,jakarta-ant1.3,
其中J2SDKEE和J2SDK1.4可以從www.Java.sun.com免費下載。
2。點擊安裝,我這邊是安裝在D盤下
3。進行環境設置:
右擊我的電腦/屬性/高級/環境變量/系統變量
點擊path,在其變量值後面加入:;D:j2sdkin;D:j2sdkeein;D:jakarta-ant1.3in;
點擊classpath,在其變量值後面加入:;D:j2sdklibdt.jar;D:j2sdklib ools.jar;D:j2sdkjrelib
t.jar;D:j2sdkeelibj2ee.jar;
其中D:j2sdkee為J2SDKEE的安裝路徑,D:j2sdk和D:jakarta=ant1.3同樣。
4。測試:
在IE中輸入:http://localhost:8000假如安裝成功就會出現J2EE的介面;
假如不行,可能是在你電腦上的8000端口被其它軟件占用了,發生了沖突。這時你就要改一下進入D:j2sdkeeconfig中把web.properties中的http.port=8000的8000改成其它沒有沖突端口號。
5。啟動J2EE
進入命令提示符,輸入:start j2ee -verbose啟動J2EE。
輸入:start deploytool啟動應用程序配置工具進行配置。
下而一個例子:
Home接口:
import java.rmi.RemoteException;
import java.io.Serializable;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface ConverterHome extends EJBHome
{
Converter create() throws RemoteException,CreateException;
}
Remote接口:
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import java.math.*;
public interface Converter extends EJBObject
{
public BigDecimal dollarToYen(BigDecimal dollars)throws RemoteException;
public BigDecimal yenToEuro(BigDecimal yen)throws RemoteException;
}
Bean類:
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.math.*;
public class ConverterBean implements SessionBean
{
BigDecimal yenRate=new BigDecimal("121.6000");
BigDecimal euroRate=new BigDecimal("0.0077");
public BigDecimal dollarToYen(BigDecimal dollars)
{
BigDecimal result=dollars.multiply(yenRate);
return result.setScale(2,BigDecimal.ROUND_UP);
}
public BigDecimal yenToEuro(BigDecimal yen)
{
BigDecimal result=yen.multiply(euroRate);
return result.setScale(2,BigDecimal.ROUND_UP);
}
public ConverterBean() {}
public void ejbCreate(){}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}
}
Client程序:
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.math.BigDecimal;
import Converter;
import ConverterHome;
public class ConverterClient
{
public static void main(String[] args)
{
try{
Context initial=new InitialContext();
Object objref=initial.lookup("java:comp/env/ejb/SimpleConverter");
ConverterHome home=(ConverterHome)PortableRemoteObject.narrow(objref,ConverterHome.class);
Converter currencyConverter=home.create();
BigDecimal param=new BigDecimal("100.00");
BigDecimal amount=currencyConverter.dollarToYen(param);
amount=currencyConverter.yenToEuro(param);
System.exit(0);
}
catch (Exception ex)
{
System.err.println("Caught an uneXPected exception!");
ex.printStackTrace();
}
}
}