java - RMI 服务器 - 模块 RMIServer 没有 "exports Server"到模块 java.rmi

标签 java rmi java-module

这是界面

package Server;

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

public interface RmiSomme extends Remote{
    
    public abstract void getInformation(String nom, String prenom, int age) throws RemoteException;
    
}

这里是实现

package Server;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class RmiSommeImpl extends UnicastRemoteObject implements RmiSomme{

    private static final long serialVersionUID = 1L;

    protected RmiSommeImpl() throws RemoteException {
        super();
        // TODO Auto-generated constructor stub
    }

    @Override
    public void getInformation(String nom, String prenom, int age) throws RemoteException {
        // TODO Auto-generated method stub
System.out.println(nom + " " + prenom);
    }

}

这是服务器类

package Server;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

public class Server {

    public static void main(String[] args) throws RemoteException, MalformedURLException {
        
        
        try {
            RmiSommeImpl rmi = new RmiSommeImpl();
            LocateRegistry.createRegistry(11);
            Naming.rebind("rmi://localhost:11/RMI", rmi);
            System.out.println(rmi.toString());
        }
        catch(Exception e) {
            System.out.println(e.getMessage());
        }
        
    }
    
}

当我启动服务器类时,此错误不断出现:

Unable to make public abstract void Server.RmiSomme.getInformation(java.lang.String,java.lang.String,int) throws java.rmi.RemoteException accessible: module RMIServer does not "exports Server" to module java.rmi

最佳答案

您必须通过将以下行添加到 module-info.java 文件中来导出您的 Server 包:

exports Server to java.rmi;

关于java - RMI 服务器 - 模块 RMIServer 没有 "exports Server"到模块 java.rmi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71459616/

相关文章:

java - 既然 tools.jar 在 Java 9 中被分解了,sun.misc.Perf 去了哪里

Java正则表达式

java - Java 中的矩阵操作 OOP

java - 计算抢占式最短作业优先调度算法的平均等待时间

java - Spring RMI错误java.lang.ClassNotFoundException : org. springframework.remoting.rmi.RmiInvocationHandler

classpath - Java 9 模块 : Can automatic Modules result in larger (full) projects?

java - StampedLock 与 Thread 类的奇怪行为

java - 无法识别“javac”且未找到 rmiregistry

java - Spring异步RMI调用

java - module-info.java 使用 maven-compiler-plugin 和自动模块编译失败