0
我正在学rmi,想出了一个问题,我解决不了。 下面是简单的代码由于找不到类而导致JAVA rmi嵌套异常
客户端代码:
package rmi_test;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class client {
public static void main(String [] args) throws RemoteException, NotBoundException
{
Registry registry = LocateRegistry.getRegistry("127.0.0.1");
DNInterface s = (DNInterface) registry.lookup("DNInterface");
if (s.test())
System.out.println("Hello World");
}
}
接口代码:
package rmi_test;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface DNInterface extends Remote{
public boolean test() throws RemoteException;
}
服务器代码:
然后我用下面的命令来编译代码
javac -cp src: src/rmi_test/DNInterface.java
javac -cp src: src/rmi_test/DataNodeImp.java
javac -cp src: src/rmi_test/client.java
然后我型
rmiregistry &
当我尝试使用
java -cp src: rmi_test.DataNodeImp to run the server
它说
Exception in thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: rmi_test.DNInterface
这有什么错用命令我运行代码? 为什么我找不到DNInterface.class?
非常感谢!
看起来你有类路径问题。这个问题的答案可能会帮助你http://stackoverflow.com/questions/1914493/add-jar-file-to-buildpath-in-windows-command-line – JRSofty