当前位置:操作系统 > Windows 2000 >>

Windows 2000 server下j2ee+jdk+ant的配置

 


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:j2sdkjrelibt.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();
}
}
}

补充:软件开发 , Java ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,