ClassNotFoundException使我发疯[duplicate]

问题描述 投票:0回答:1

我正在尝试运行Java网站中提供的这个基本RMI示例:https://docs.oracle.com/javase/7/docs/technotes/guides/rmi/hello/hello-world.html

而且它不会运行,因为我认为它找不到interface。它总是抛出此异常:

java.lang.ClassNotFoundException: Hello

这里是接口的代码:

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Hello extends Remote {
    String sayHello() throws RemoteException;
}

服务器的代码为

import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class Server implements Hello {

    public Server() {}

    public String sayHello() {
        return "Hello, world!";
    }

    public static void main(String args[]) {

        try {
            Server obj = new Server();
            Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);

            // Bind the remote object's stub in the registry
            Registry registry = LocateRegistry.getRegistry();
            registry.bind("Hello", stub);

            System.err.println("Server ready");
        } catch (Exception e) {
            System.err.println("Server exception: " + e.toString());
            e.printStackTrace();
        }
    }
}

我也将接口添加到了我的类路径中。我的类路径包含以下条目:

 - C:\Users\mkris\Desktop\untitled\src\Hello.class

 - C:\Users\mkris\Desktop\untitled\src\Hello.java   
 - C:\Users\mkris\Desktop\untitled\src

我正在使用IntelliJ IDE。我的src文件夹包含三个.java文件和相应的.class文件。我几乎整天都在尝试解决此问题,这让我发疯。我几乎要把笔记本电脑折成两半。请帮帮我。

谢谢!

java rmi classnotfoundexception
1个回答
-1
投票

@@ Doctor ..是否有使用Javase 7的要求?看看JDK 8的实现https://docs.oracle.com/javase/tutorial/rmi/implementing.html

© www.soinside.com 2019 - 2024. All rights reserved.