开发者

RMI Connection error Client Side

I am getting an error when attempting to connect to an RMI service:

I am executing the client code using:

java -Djava.security.manager -Djava.security.policy=path\to\policy.all -jar "path\to\jarfile" "localhost:2020"

The code I am using is:

public class PowerServiceClient
{
    public static void main(String args[]) throws Exception
    {

         System.setSecurityManager
            (new RMISecurityManager());

         // Call registry for PowerService
         PowerService service = (PowerService) Naming.lookup
            ("rmi://localhost:2020/PowerService");

         DataInputStream din = new
             DataInputStream (System.in);

    }
}

The error I am receiving is:

    Exception in thread "main" java.rmi.UnmarshalException: 
    error unmarshalling return; nested exception is:

    java.lang.ClassNotFoundException: rmiservice.PowerService
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at java.rmi.Naming.lookup(Unknown Source)
    at powerclient.PowerServiceClient.main(PowerServiceClient.java:32)
    Caused by: java.lang.ClassNotFoundException: rmiservice.PowerService
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Meth开发者_C百科od)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at sun.rmi.server.LoaderHandler.loadProxyInterfaces(Unknown Source)
    at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
    at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
    at java.rmi.server.RMIClassLoader$2.loadProxyClass(Unknown Source)
    at java.rmi.server.RMIClassLoader.loadProxyClass(Unknown Source)
    at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
    at java.io.ObjectInputStream.readProxyDesc(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.readObject(Unknown Source)
    ... 3 more

Does anyone know what the problem is here?


The Registry needs access to your remote interface class and its dependencies on its classpath. There are three solutions to that. In order of ease:

  1. Start the Registry inside your server JVM, with LocateRegistry.createRegistry()
  2. Start the rmiregistry process with a -D-Jclasspath= argument
  3. Use the codebase feature.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜