[help]编译j2ee tutorial 第一个例子出错!
xlhl 2003-12-14 11:51:16 初学java 编译j2ee tutorial 第一个例子遇到问题,请指点!!!!
j2ee_home,path已经设置正确
------------------------------------------------------------------------------------
//ConverterHome.java
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface ConverterHome extends EJBHome {
public Converter create() throws RemoteException, CreateException;
}
-----------------------------------------------------------------------------------
编译结果:
E:\j2eetutorial\examples\src\ejb\converter>javac ConverterHome.java
ConverterHome.java:17: cannot resolve symbol
symbol : class Converter
location: interface ConverterHome
public Converter create() throws RemoteException, CreateException;
^
1 error
======================================================================================
//ConverterClient.java
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();
Context myEnv = (Context)initial.lookup("java:comp/env");
Object objref = myEnv.lookup("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);
System.out.println(amount);
amount = currencyConverter.yenToEuro(param);
System.out.println(amount);
System.exit(0);
} catch (Exception ex) {
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}
}
-----------------------------------------------------------------------------------------
编译结果:
E:\j2eetutorial\examples\src\ejb\converter>javac ConverterClient.java
ConverterClient.java:15: '.' expected
import Converter;
^
ConverterClient.java:16: '.' expected
import ConverterHome;
^
ConverterClient.java:26: cannot resolve symbol
symbol : class ConverterHome
location: class ConverterClient
ConverterHome home =
^
ConverterClient.java:27: cannot resolve symbol
symbol : class ConverterHome
location: class ConverterClient
(ConverterHome)PortableRemoteObject.narrow(objref,
^
ConverterClient.java:28: cannot resolve symbol
symbol : class ConverterHome
location: class ConverterClient
ConverterHome.class);
^
ConverterClient.java:30: cannot resolve symbol
symbol : class Converter
location: class ConverterClient
Converter currencyConverter = home.create();
^
6 errors
=================================================================================
以下两个文件正确编译
//Converter.java
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;
}
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.math.*;
//ConverterBean.java
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) {}
}