I have fallen victim to the following Java RMI bug, as noted in the JDK 7 release notes:
A bug in the rmiregistry command included in this release may cause unintended exceptions to be thrown when an RMI server attempts to bind an exported object which includes codebase annotations using the "file:" URL scheme. The RMI servers most likely to be effected are those which are invoked only by RMI clients executing on the same host as the server.
RMI annotates codebase information as part of the serialized state of a remote object reference to assist RMI clients in loading the required classes and interfaces associated with the object at runtime. Exported objects which are looked up in the RMI registry and invoked by RMI clients running on hosts other than the server are usually annotated with codebase URL schemes, such as "http:" or "ftp:" and these should continue to work correctly.
As a workaround, RMI servers can set the java.rmi.server.codebase property to use codebase URLs other than the "file:" scheme for the objects they export.
(emphasis mine)
I am developing a RMI application on my local machine and I need to set the codebase to include some libraries.
StringBuilder codebase = new StringBuilder();
codebase.append(" file:/").append(projectPath).append("/bin/lib/rmiio-2.0.0.jar")
.append(" file:/").append(projectPath).append("/bin/lib/log4j-1.2.9.jar")
.append(" file:/").append(projectPath).append("/bin/lib/commons-logging.jar")
.append(" file:/").append(projectPath).append("/bin/lib/commons-logging-api.jar");
System.setProperty("java.rmi.server.codebase", codebase.toString());
How can I achieve the same without the ‘file:/’ syntax? What is a valid workaround for the bug in my situation?
If there is a bug with the file URL scheme
(and I guess you validated that the syntax is for example –
file:///home/user/myprojects/myjar.jar)I guess you have no other option than either to fix the issue in open JDK, or to put the files in an apache webserver (or tomcat for this matter) and use URIs with the “http://” prefix.
A deployment of such tomcat or apache is quite simple, as you’re dealing here with static resources.
From what I remember, and after I looked here I see no other option but to provide a chain of URIs to codebase, as you did.
Another option is to simply provide this jars with the RMI client code.