Java ArchLinux/CentOS中RMI Naming.rebind()中的FormedUrlexception错误
我有两台使用RMI连接的服务器,一台服务器和一台BServer 服务器的相关代码为:Java ArchLinux/CentOS中RMI Naming.rebind()中的FormedUrlexception错误,java,linux,exception,rmi,Java,Linux,Exception,Rmi,我有两台使用RMI连接的服务器,一台服务器和一台BServer 服务器的相关代码为: int port = Integer.parseInt("1234"); String url = "rmi://localhost:" + port + "/Aclass"; System.out.println("binding " + url); Naming.rebind(url, new AClass()); int port = Integer.parseInt("1234"); String u
int port = Integer.parseInt("1234");
String url = "rmi://localhost:" + port + "/Aclass";
System.out.println("binding " + url);
Naming.rebind(url, new AClass());
int port = Integer.parseInt("1234");
String url = "//localhost:" + port + "/Bclass";
System.out.println("binding " + url);
Naming.rebind(url, new BClass());
观察者的相关代码为:
int port = Integer.parseInt("1234");
String url = "rmi://localhost:" + port + "/Aclass";
System.out.println("binding " + url);
Naming.rebind(url, new AClass());
int port = Integer.parseInt("1234");
String url = "//localhost:" + port + "/Bclass";
System.out.println("binding " + url);
Naming.rebind(url, new BClass());
在ArchLinux/CentOS上,当我为服务器运行以下命令时:
java -cp ".:./protobuf.jar" -Djava.rmi.server.codebase=protobuf.jar -Djava.security.policy=policy AServer
以及BServer的相应代码:
java -cp ".:./protobuf.jar" -Djava.rmi.server.codebase=protobuf.jar -Djava.security.policy=policy BServer
而对于服务器,控制台打印:
binding rmi://localhost:1234/AServer
server rmi://localhost:1234/AServer is running...
观察者打印:
binding rmi://localhost:1234/BServer
Place server failed:Error unmarshaling return; nested exception is:
java.net.MalformedURLException: no protocol: protobuf.jar
java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
java.net.MalformedURLException: no protocol: protobuf.jar
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:247)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:379)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:177)
at BServer.main(BServer.java:31)
Caused by: java.net.MalformedURLException: no protocol: protobuf.jar
at java.net.URL.<init>(URL.java:586)
at java.net.URL.<init>(URL.java:483)
at java.net.URL.<init>(URL.java:432)
at sun.rmi.server.LoaderHandler.pathToURLs(LoaderHandler.java:770)
at sun.rmi.server.LoaderHandler.getDefaultCodebaseURLs(LoaderHandler.java:141)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:170)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:637)
这表明错误一定出现在Name.rebind命令中,但据我所知,URL的格式很好,所以我被难住了
这两台服务器在Mac OS中都可以正常工作,并使用以下命令运行:
java-cp.:./protobuf.jar-Djava.security.policy=policyaserver
它们按照我的要求完美地工作,但是在ArchLinux/CentOS中,我需要添加
-Djava.rmi.server.codebase=。。。或者我得到一个NoClassDefFoundError。代码基规范的元素是URL,而不是文件名。您尚未指定协议或绝对路径
反正也不行。java.rmi.server.codebase必须以对等方可理解的形式表示。仅仅重复a classpath元素是不够的。谢谢您的回复,但您没有指定协议或绝对路径是什么意思。?你是说我根本不应该使用java.rmi.server.codebase吗?在这种情况下,我得到一个NoClassDefFoundError..?我所说的“您没有指定协议或绝对路径”是指规范-Djava.rmi.server.codebase=protobuf.jar既不包含协议也不包含绝对路径。我怀疑您是否真的需要使用代码库功能,当然不是在初学者阶段。那么您将如何着手解决这个问题呢?我很确定我们不需要代码库部分…所以删除它,并确保注册表和客户端的类路径上都有.jar文件。服务器和客户端都有对相同.jar文件的引用,但仍然有相同的错误。。。