我正在尝试测试java的RMI,但我无法使rmic命令工作。

请告诉我您是否需要我的代码,尽管我非常确定这无关紧要,但我已经正确地实现了RMI函数。
服务器端代码:
public static void main(String[] args)
{
try {
Registry r = LocateRegistry.getRegistry();
r.bind("RService", new RSimpl());
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("Cannot Start Remote Service");
}
System.out.println("Remote Service Is Running");
} 客户端代码:
@SuppressWarnings("deprecation")
public Object[] getServiceList()
{
boolean connectionsuccess = false;
Object[] objList = null;
try {
System.setSecurityManager(new RMISecurityManager());
server = (RemoteService) Naming.lookup("rmi://192.168.1.77/RService");
connectionsuccess = true;
}
catch(Exception ex) {
Object[] options = {"Retry","Cancel"};
int o = JOptionPane.showOptionDialog(frame, "Cannot Establish Connection To The Server. \n Do You Want To Retry?", "Connection Error", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);
if(o==0)
{
i=0;
attemptConnect();
}
else
{
i=1;
return error;
}
}
}RSimpl.java:
package testrmi;
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.*;
import java.util.*;
public class RSimpl extends UnicastRemoteObject implements RemoteService {
HashMap map;
public RSimpl() throws RemoteException
{
setUpServices();
}
public void setUpServices()
{
map = new HashMap();
map.put("Dice Roll Service", new DiceRoll());
map.put("Calculator Service", new Calculator());
// Keep Adding Services On The Go!
}
public Object[] getServiceList()
{
return map.keySet().toArray();
}
public Service getService(Object SvcKey)
{
Service theService = (Service) map.get(SvcKey);
return theService;
}
public static void main(String[] args)
{
try {
Registry r = LocateRegistry.getRegistry();
r.bind("RService", new RSimpl());
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("Cannot Start Remote Service");
}
System.out.println("Remote Service Is Running");
}
}RemoteService.java (接口):
package testrmi;
import java.rmi.*;
public interface RemoteService extends Remote {
public Object[] getServiceList() throws RemoteException;
public Service getService(Object SvcKey) throws RemoteException;
}发布于 2017-07-17 21:17:10
名为testrmi.RSImpl的类的类文件必须位于相对于testrmi/RSImpl.class中指定的目录之一的CLASSPATH中。
发布于 2017-07-17 19:25:05
似乎在这种情况下找不到文件。尝试在cmd中键入dir以查看您的文件夹是否在那里。您还可以导航到testrmi文件夹并输入rmic RSimpl。
如果仍然不起作用,请尝试将所需的文件复制到桌面上的文件夹中,然后导航到该文件夹并进行测试。
发布于 2017-07-17 21:12:02
很抱歉我问了这么愚蠢的问题。我没有按照oracle上的RMIC文档中的定义添加类路径。对于面临此问题的其他任何人,请打开系统环境变量并添加这两个path变量:
您必须添加DOT path变量以及已编译类的路径
https://stackoverflow.com/questions/45142381
复制相似问题