Ho una semplicissima applicazione rmi (si trova nel tutorial di java rmi) per testare le funzionalità codebase , il mio intento è quello di eseguire un'applicazione client che scarica una classe (non presente nel suo classpath locale, ma presente nel codebase) direttamente da remoto....
SERVER-SIDE:
codice:public interface HelloInterfaces extends Remote, Serializable { public void ok() throws RemoteException; }codice:public class Hello extends UnicastRemoteObject implements HelloInterfaces{ public Hello() throws RemoteException{ super();} @Override public void ok() throws RemoteException { } }codice:public class Server { public static void main(String[] arg) throws RemoteException, NamingException { System.setProperty("java.rmi.server.codebase", "http://localhost:8080/"); System.setProperty("java.security.policy", "file.policy"); System.setSecurityManager(new RMISecurityManager()); Registry reg = LocateRegistry.createRegistry(1099); HelloInterfaces h=new Hello(); reg.rebind("Hello", h); System.out.println("Ready"); } }
CLIENT-SIDE
codice:public class Client { public static void main(String[] args) throws RemoteException, NotBoundException, MalformedURLException, NamingException { String host="localhost"; if (args.length > 0) { host = args[0]; } System.setProperty("java.security.policy", "file.policy"); System.setSecurityManager(new RMISecurityManager()); System.setProperty("java.rmi.server.codebase", "http://" + host + ":8080/"); System.out.println(host); Registry reg = LocateRegistry.getRegistry(host); System.out.println("Registry ok"); HelloInterfaces o = (HelloInterfaces) reg.lookup("Hello"); System.out.println(o); } }
lancio un http server nella cartella che contiene tutti i .class (giusto per testing) del server.
eseguo il server:
"Ready"
eseguo il client:
restituisce l'errore proprio in corrispondenza dell'operazione di lookup....codice:localhostRegitry Found! Exception in thread "main" java.lang.NoClassDefFoundError: base/HelloInterfaces at client.Client.main(Client.java:39) Caused by: java.lang.ClassNotFoundException: base.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.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 1 more
il client scarica effettivamente il file HelloInterfaces.class perché me lo dice l'httpserver... ma nonostante ciò ottengo questo errore....
cosa può essere?

Rispondi quotando