我无法理解如何使用代码库。
我有以下结构:
CLIENT:
Client.java
client.policy
SERVER:
Server.java
Hello.java
HelloInterfaces.java
HelloInterfaces.java
public interface HelloInterfaces extends Remote {
}
Hello.java
public class Hello extends UnicastRemoteObject implements HelloInterfaces{
public Hello() throws RemoteException{
}
}
Server.java
public class Server {
public static void main(String[] arg) throws RemoteException {
Registry reg = LocateRegistry.createRegistry(1099);
reg.rebind("Hello", new Hello());
System.out.println("Ready");
}
}
Client.java
public class Client {
public static void main(String[] args) throws RemoteException, NotBoundException, MalformedURLException {
String host="192.168.1.227"; //IP SERVER
System.setProperty("java.rmi.server.codebase", "http://" + host + ":8080");
System.setProperty("java.security.policy", "client.policy");
System.setSecurityManager(new RMISecurityManager());
Registry reg = LocateRegistry.getRegistry(host);
System.out.println("Regitry Found!");
System.out.println(reg.list().length);
System.out.println(reg.list()[0]);
HelloInterfaces h;
h = (HelloInterfaces) reg.lookup("Hello");
System.out.println(h);
}
}
client.policy
grant {
permission java.security.AllPermission;
};
直接从Netbeans在服务器(使用Linux的虚拟机)上执行: 输出服务器:准备就绪!
在客户端上,我使用选项--classpath .:Server.jar
编译源代码(其中Server.jar包含HelloInterfaces.class)。
执行客户端:
Output Client: Registry Found! 1 Hello (Running......)
两分钟后:
Exception in thread "main" java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: HelloInterfaces
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at Client.main(Client.java:36)
Caused by: java.lang.ClassNotFoundException: HelloInterfaces
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.rmi.server.LoaderHandler$Loader.loadClass(LoaderHandler.java:1206)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at sun.rmi.server.LoaderHandler.loadClassForName(LoaderHandler.java:1219)
at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:729)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:673)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:610)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:646)
at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:311)
at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:255)
at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1558)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
... 2 more
此外,在包含.class
的目录服务器上,我在端口8080上运行python httpserver。
(与NanoHTTP相同的结果,用java编写的http服务器)
app客户端与http服务器联系,因为python httpserver输出:
192.168.1.24 - - "GET / HTTP/1.1" 200 -
答案 0 :(得分:1)
代码库是包含.class文件的包结构化层次结构的JAR文件或目录的URL列表。主机和端口专用URL似乎不太可能符合该描述。