这是界面
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/