第一个EJB便遇到了麻烦,请赐教!谢谢!
这是我的客户端
package client;
import agency.*;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import java.util.*;
public class SimpleClient
{
//每个J2EE组件的名称空间内都有一个称为java:comp/env/的环境
//用来存储该组件所需的对资源的引用
private static String agencyJNDI = "java:comp/env/ejb/Agency";
public static void main(String[] args) {
if (args.length == 1)
agencyJNDI = args[0];
else if (args.length > 1) {
System.err.println("Usage: SimpleClient [ AgencyJNDI ]");
System.exit(1);
}
try {
Properties props=System.getProperties();
//初始化的Context是连接JNDI树的起始点
//我们通过传递环境属性来选择JNDI驱动器和服务器的网络位置等
InitialContext ic = new InitialContext(props);
//lookup获取所需组件,下面获得angencyJNDI数据源
//名字agencyJNDI被定义为java组件环境内部的EJB引用
Object lookup = ic.lookup(agencyJNDI);
//home 对象是RMI-IIOP对象,所以它们必须使用一个特殊的RMI-IIOP造型
//被改造为RMI-IIOP对象
AgencyHome home = (AgencyHome)PortableRemoteObject.narrow(lookup, AgencyHome.class);
//使用制作生成库生成EJB对象
Agency agency = home.create();
//在EJB对象中调用getAgencyName(),getCustomers()方法;
//EJB对象将把调用委派给Bean,并接受结果和把结果发送给我们
System.out.println("Welcome to: "+agency.getAgencyName());
System.out.println("Customer list: "+agency.getAgencyName());
Collection customers = agency.getCustomers();
Iterator it = customers.iterator();
while (it.hasNext())
{
String name = (String)it.next();
System.out.println(name);
}
System.out.println("\nDone\n");
agency.remove();
}
catch (NamingException ex) {
System.err.println(ex);
}
catch (ClassCastException ex) {
System.err.println(ex);
}
catch (CreateException ex) {
System.err.println(ex);
}
catch (RemoteException ex) {
System.err.println(ex);
}
catch (RemoveException ex) {
System.err.println(ex);
}
}
}
出现了下面的错误,请帮忙解答一下啊!弄了一天了!拜托哈!
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial