wood burning stoves*
The moose likes Distributed Java and the fly likes Problem with Server RMI CODEBASE, [ClassNotFoundException] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Problem with Server RMI CODEBASE, [ClassNotFoundException]" Watch "Problem with Server RMI CODEBASE, [ClassNotFoundException]" New topic
Author

Problem with Server RMI CODEBASE, [ClassNotFoundException]

Jo Mcdonald
Greenhorn

Joined: May 05, 2014
Posts: 4
I can not understand how to use the codebase...
I have the following structure:


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;
};


Execute on server (Virtual Machine with Linux) directly from Netbeans:
Output Server: Ready!


on the client, I have compiled the source with option --classpath .:Server.jar (where Server.jar contains HelloInterfaces.class).

execute Client:
Output Client:
Registry Found!
1
Hello

(Running......)
and after two minutes....

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

Also, on directory server that contains .class, I run a python httpserver on port 8080.
(same result with a NanoHTTP, http server written in java)


The app client contacts the http server because python httpserver output :
192.168.1.24 - - "GET / HTTP/1.1" 200 -
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18655
    
    8

First of all it won't work if you put the source code (the .java files) on the server where it expects to find the code base. It needs the compiled code (the .class files) to work properly.

And second of all, I would recommend that you put your classes into a package. It may be that it isn't possible for the server to load classes which aren't in a package.

As for the HTTP server, I would look more closely at the logs to make sure that it's the correct class files which are being sent back from the server.
Jo Mcdonald
Greenhorn

Joined: May 05, 2014
Posts: 4
Paul Clapham wrote:First of all it won't work if you put the source code (the .java files) on the server where it expects to find the code base. It needs the compiled code (the .class files) to work properly.

And second of all, I would recommend that you put your classes into a package. It may be that it isn't possible for the server to load classes which aren't in a package.

As for the HTTP server, I would look more closely at the logs to make sure that it's the correct class files which are being sent back from the server.



So, I have moved the server classes in a package ("base").
Also, I made a further change: HelloInterfaces extends also Serializable.



Now, the hierarchical structure of the server is the following:




the main server (IP 192.168.1.32) I run it directly from the IDE.

Output Server (APP SERVER):


HTTPSERVER:
open the shell, and launch the httpserver on port 8080 in the directory that contains all the file hierarchy.'s server class (including the package "base")

OUTPUT (HTTPSERVER):




an another machine in LAN, launch the file ClientApp.jar


this is her contents:


Output client (ClientApp.jar):


and in this moment, the HTTPSERVER :


but, after two minutes the client:


I can not understand why... (App Server nothing output)...
Where is the error?What's wrong?
Jo Mcdonald
Greenhorn

Joined: May 05, 2014
Posts: 4
up
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Server RMI CODEBASE, [ClassNotFoundException]