关于rmi-iiop和jndi的问题
我在学习rmi-iiop和jndi中碰到问题,请高手帮忙看一下
有四个文件
IPKGenerator.java:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface IPKGenerator extends Remote{
public long generate()throws RemoteException;
}
PKGenerator.java:
import java.rmi.RemoteException;
import javax.rmi.PortableRemoteObject;
public class PKGenerator extends PortableRemoteObject implements IPKGenerator{
public PKGenerator()throws Exception,RemoteException{
super();
}
public synchronized long generate()throws RemoteException{
return i++;
}
private static long i=System.currentTimeMillis();
}
Startup.java:
import javax.naming.*;
public class Startup{
public static void main(String[] args)throws Exception{
PKGenerator generator=new PKGenerator();
Context ctx=new InitialContext(System.getProperties());
ctx.rebind("PKGenerator",generator);
System.out.println("PKGenerator bound to JNDI tree.");
synchronized(generator){
generator.wait();
}
}
}
Client.java:
import javax.naming.*;
import java.rmi.*;
public class Client{
public static void main(String[] args)throws Exception{
Context ctx=new InitialContext(System.getProperties());
Object remoteObject=ctx.lookup("PKGenerator");
IPKGenerator generator=(IPKGenerator)javax.rmi.PortableRemoteObject.narrow(remoteObject,IPKGenerator.class);
System.err.println(generator.generate());
}
}
我用rmic编译了PKGenerator生成了根程序和程序框架,在运行Startup.java时抛出了NoInitialContextException异常,那位高手能告诉我该怎么样编译和执行这几个文件,小弟我刚学j2ee,请多指点,希望能尽量详细点,谢谢!