java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: [java] java.net.ConnectException: Connection refused (Connection refused)
尽管我已经完成了迄今为止在论坛上找到的所有提示,但在运行我的 Ant build.xml时出现此错误。
构建.xml 文件
<dirname property="basedir" file="." />
<target name="compile">
<mkdir dir="${basedir}/bin" />
<javac srcdir="${basedir}/src" destdir="${basedir}/bin" />
</target>
<target name="clean" description="cleanup module">
<delete dir="${basedir}/bin" />
</target>
<target name="run" depends="compile">
<parallel>
<java classpath="${basedir}/bin" classname="com.main.MainServer"
fork="true">
<jvmarg value="-Djava.security.policy=server.policy" />
</java>
<sequential>
<java classpath="${basedir}/bin" classname="com.main.MainClient">
<jvmarg value="-Djava.security.policy=client.policy" />
</java>
</sequential>
</parallel>
</target>
客户政策
grant{
permission java.security.AllPermission;
};
服务器策略
grant{
permission java.security.AllPermission;
};
创建和运行 RMI 注册表
public void bindServer() {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
System.setProperty("java.rmi.server.hostname", InetAddress.getLocalHost().getHostAddress());
server = (IServer) UnicastRemoteObject.exportObject(new Server(), IConstant.RMI_PORT_SERVER);
Registry registry = LocateRegistry.createRegistry(IConstant.RMI_PORT_SERVER);
registry.rebind(IConstant.RMI_ID_SERVER, server);
} catch (RemoteException e) {
System.err.println("Server RemoteException:");
e.printStackTrace();
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
我的 /etc/hosts 文件
127.0.0.1 localhost
127.0.0.1 mylaptop
127.0.0.1 postgres
127.0.0.1 java.rmi.server.hostname
任何帮助将不胜感激。