RMI Registry Issue: rmiregistry may cause unintended exceptions when binding with codebase using the “file:” URL scheme

*爱你&永不变心* 提交于 2019-12-06 11:29:54

I had the same problem, and can confirm that downgrading JDK to earlier version solves the problem. I know, it's not a solution you're looking for, but at least it makes it to work.

hejiaming007

Take running in windows as an example:

Step 1. In C:\Users\Jimmy.java.policy (create it if not exist), append below content:

grant { permission java.security.AllPermission; };

Of course "C:\Users\Jimmy\" is the user home, please change to your home accordingly. Adding AllPermission is just for quick resolving your issue. you'd better config a more accurate FilePermission here.


Step 2. Start rmiregistry:

C:\JDK\bin>rmiregistry -J-Djava.rmi.server.codebase=file://C:/workspaces/MyLab/target/classes/

(Please note codebase must ended with "/")


Step 3. Run your server and client program.

References:

http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/codebase.html http://docs.oracle.com/javase/7/docs/technotes/guides/security/spec/security-spec.doc3.html http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/enhancements-7.html

It looks like there is no workaround because it is a bug, so wait for the fix

See details at

https://bugzilla.redhat.com/show_bug.cgi?id=751203

Code fix http://icedtea.classpath.org/hg/icedtea6/rev/67df573b0734

If you do not need dynamic code downloading (in which case you can use ftp codebase) the solution is simply to set CLASSPATH environment variable to the path to your jar file:

Windows: set CLASSPATH="path_to_jarfile"

Linux (batch): CLASSPATH="path_to_jarfile" export CLASSPATH

Best place to do it is in some script that invokes the RMI server. Setting class path in the command line (-cp option) when starting RMI server does not help because it does not affect rmiregistry classpath!

If you start the rmiregistry in the working directory of your project, it works. So essentially working directory of your project and current directory for rmiregistry should be same.

I recently encountered this issue as well. I can confirm that when using the file: protocol the rmiregistry must either:

  • be started in the root of the directory containing the shared classes; or
  • set the classpath to point to the shared classes or shared class jar; or
  • use a protocol other than file:// (I set up ngnix and served the jar from that).

Maybe not what you want, but you could resolve this with classpath rather than codebase. The client JVM will work fine if you add the required classes to its classpath. If you are using the file: URL scheme, then the classes must already be available on the localhost.

I had the same problem but I couldn't change the JDK version. Turns out you can solve it by running/starting the rmiregistry from the same directory as your code base, which in my case was target/classes. So cd project/target/classes and then run rmiregistry &

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!