I'm working on Java RMI application.
For client using java 7 runs everything correctly.
But for client using java 1.4.2.
The server runs on Windows XP with java 7.
Service Interface:
package rmiserver;
import java.rmi.*;
public interface ServiceInterface extends Remote {
public static final int port=1099;
public String getString(Integer n) throws RemoteException;
}
Service Implementation:
package rmiserver;
import java.rmi.*;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class ServiceImplementation extends UnicastRemoteObject implements ServiceInterface{
public ServiceImplementation() throws RemoteException {
try {
} catch (Exception e) {
System.out.println("Error:" + e.toString());
}
}
public String getString(Integer n) throws RemoteException {
return n.toString();
}
public static void main(String[] args) { // Por ej. en el main del servidor RMI
int port = ServiceInterface.port;
System.setSecurityManager(new RMISecurityManager());
try {
java.rmi.registry.LocateRegistry.createRegistry(port);
} catch (Exception e) {
System.out.println(e.toString() + "Rmiregistry OK.");
}
try {
ServiceImplementation service = new ServiceImplementation();
String machine = "//192.168.1.3" + ":" + port;
String name_service = "/serviceString";
String serviceRemoto = machine + name_service;
Naming.rebind(serviceRemoto, service);
System.out.println("....OK.....");
} catch (Exception e) {
System.out.println("Error: " + e.toString());
}
}
}
Client:
package rmiclient;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import rmiserver.ServiceInterface;
public class RMIClient {
public static void main(String[] args) {
try {
ServiceInterface service;
String name_service = "/serviceString";
System.setSecurityManager(new RMISecurityManager());
int port = ServiceInterface.port;
String machine = "192.168.1.3";
service = (ServiceInterface) Naming.lookup("rmi://" + machine + ":" +port + name_service);
System.out.println("OUTPUT: "+service.getString(new Integer(23)));
} catch (Exception e) {
e.printStackTrace();
}
}
}
On the client and on the server I have the following java.policy:
grant {
permission java.security.AllPermission;
};
On the server side I have the "Service" folder, under this I have:
RmiServer.bat:
java -classpath RmiServer.jar -Djava.rmi.server.codebase=file:RmiServer.jar -Djava.security.policy=java.policy -jar RmiServer.jar
On the client side I have the "Client" folder, under this I have:
RMIClient.bat:
java -classpath lib -Djava.rmi.server.codebase=file:lib -Djava.security.policy=java.policy -jar RMIClient.jar
I generated the stub as follows:
rmic -classpath RmiServer.jar -d stub_folder rmiserver.ServiceImplementation
I have the following error to run the client in java 1.4.2 :
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: java.rmi.server.RemoteObjectInvocation
Handler
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at rmiclient.RMIClient.main(RMIClient.java:17)
Caused by: java.lang.ClassNotFoundException: java.rmi.server.RemoteObjectInvocat
ionHandler
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
... 3 more
Thanks for any help.
You are running a 1.5+ server without a stub, which causes a dynamic stub to be used, in the form of a dynamic proxy and an RemoteObjectInvocationHandler, and a 1.4 client, which doesn't have the RemoteObjectInvocationHandler class in the JRE.
You need to run 'rmic' and deploy the stub correctly at the server and clients. You haven't deployed the stub class correctly at server and client. It isn't even being found at the server. It should be in the JAR file at both ends, not in some weirdo directory unknown to the CLASSPATH.
Or update the clients to use a current JDK. 1.4 is many years past end of life.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.