1。所先下载j2sdkee1.3和j2sdk1.4,jakarta-ant1.3,
其中j2sdkee和j2sdk1.4可以从www.java.sun.com免费下载。
2。点击安装,我这边是安装在d盘下
3。进行环境设置:
右击我的电脑/属性/高级/环境变量/系统变量
点击path,在其变量值后面加入:;d:/j2sdk/bin;d:/j2sdkee/bin;d:/jakarta-ant1.3/bin;
点击classpath,在其变量值后面加入:;d:/j2sdk/lib/dt.jar;d:/j2sdk/lib/tools.jar;d:/j2sdk/jre/lib/rt.jar;d:/j2sdkee/lib/j2ee.jar;
其中d:/j2sdkee为j2sdkee的安装路径,d:/j2sdk和d:/jakarta=ant1.3同样。
4。测试:
在ie中输入:http://localhost:8000如果安装成功就会出现j2ee的介面;
如果不行,可能是在你电脑上的8000端口被其它软件占用了,发生了冲突。这时你就要改一下进入d:/j2sdkee/config中把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();
}
}
}
闽公网安备 35060202000074号