简体   繁体   English

RMI远程服务器接口上的Java ClassNotFound异常

[英]Java ClassNotFound Exception on RMI remote Server Interface

This is the code of my server main 这是我的服务器主代码

public static void main(String Args[]){
      try {
        masterDAO = MasterDAO.getInstance();
    } catch (MasterException e) {
        e.printStackTrace();
        LOGGER.log(Level.SEVERE,e.getMessage() + "MASTER SHUTDOWN");
        System.exit(1);
    }
    final int REGISTRYPORT = 1499;
    String registryHost = "localhost";
    String serviceName = "MasterService";
    try {
        String completeName = "//" + registryHost + ":" + REGISTRYPORT + "/" + serviceName;
        System.out.println(completeName);
        MasterInterface master = (MasterInterface) new Master();
        registry = LocateRegistry.createRegistry(REGISTRYPORT);
        registry.rebind(completeName, master);
        System.out.println("Master Bound ");
    }
    catch (Exception e) {
        System.err.println("Master exception: ");
        e.printStackTrace();
    }
}

And this is a method on the client side : 这是客户端上的一种方法:

public FileLocation getFileLocation(String fileName, String operation){

    final int REGISTRYPORT = 1499;
    String serviceName = "MasterService";
    String completeName = "//" + "localhost" + ":" + REGISTRYPORT + "/" + serviceName;
    try {
        System.out.println(completeName);
        Registry masterRegistry = LocateRegistry.getRegistry(1499);
        System.out.println(globalInformation.getHost() + " "+REGISTRYPORT);
        MasterInterface master = (MasterInterface) masterRegistry.lookup(completeName);
        //System.out.println("Get File Location - Result: " + fileLocation.isResult() + " - Port: "+ fileLocation.getFilePositions());
        return master.checkFile(fileName,operation);
    }
    catch (NotBoundException | IOException e) {
        e.printStackTrace();
    }  catch (FileNotFoundException e) {

        System.out.println("ERROR 404 FILE NOT FOUND");
    } catch (MasterException e) {

        System.out.println("ERROR 500 INTERNAL SERVER ERROR");
    }
    return  null;
}

I'm getting this exception 我收到这个例外

java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
java.lang.ClassNotFoundException: MasterInterface (no security manager: RMI class loader disabled)
at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:127)
at com.sdcc_project.cloudlet.controller.CloudLetController.getFileLocation(CloudLetController.java:125)
at com.sdcc_project.cloudlet.controller.CloudLetController.writeToMaster(CloudLetController.java:149)
at com.sdcc_project.cloudlet.CloudletApplication$3.run(CloudletApplication.java:126)
Caused by: java.lang.ClassNotFoundException: MasterInterface (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:556)
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:265)
at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1800)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1748)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2042)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1573)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:431)
at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:123)
... 3 more

The server is executed locally launching its main , the client side is executed like a spring application on a tomcat server. 服务器在本地启动其main执行,客户端在tomcat服务器上像spring应用程序一样执行。 Before deployng on spring i used to run the client like a normal application and all was working perfectly,so i think maybe the problem is on tomcat classpath? 在春季部署之前,我曾经像正常应用程序一样运行客户端,并且一切运行正常,所以我认为问题可能出在tomcat类路径上? this is the the package of the project --> 这是项目的软件包->

在此处输入图片说明

Having different package name for the shared classes and interfaces (eg MasterInterface ) on the server vs. client side application can cause this problem. 服务器与客户端应用程序上的共享类和接口(例如MasterInterface )具有不同的包名称可能会导致此问题。

Check both projects and make sure that it has the same naming in both. 检查两个项目,并确保两个项目都具有相同的命名。 Try to achieve the same hierarchy, eg.: 尝试实现相同的层次结构,例如:

package com.xx.yy.server_intarface;  // same in server and client application

public interface MasterInterface { ...

This solved the problem , but not only the "package" value must be the same also all the import path. 这解决了问题,但不仅“包”值必须相同,而且所有导入路径也必须相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM