我有RMI应用程序,所以我需要使用策略文件。
I have got RMI application, so I need to use policy files.
我的政策文件很简单(conf.txt):
my policy file is simple (conf.txt):
grant { permission java.security.AllPermission; };从eclipse运行我的应用程序没有问题。我已经添加了:-Djava.security.policy = conf.txt到VM参数。
I have no problems running my application from eclipse. I've added: -Djava.security.policy=conf.txt to the VM arguments.
我想要做的是构建一个jar文件。我把它作为来自eclipse的Runnable JAR文件,我在运行它时遇到了一些问题。我尝试像这样运行它:
What I want to do is to build a jar file. I made it as Runnable JAR file from eclipse and I'm having some problems running it. I try to run it like this:
java -Djava.security.policy=C:\Users\myuser\proj\conf.txt -jar C:\Users\myuser\proj\proj.jar我得到与没有-Djava.security.policy选项相同的结果。
I get the same result as without -Djava.security.policy option.
我的代码:
System.setProperty("java.security.policy", "./conf.txt"); ... if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); }如何才能使这个工作?如果我不必传递-Djava.security.policy就更好了:
How can I make this working? It would be even better if I don't have to pass -Djava.security.policy just:
java -jar myprog.jar推荐答案
首先,删除您的代码中的System.setProperty(java.security.policy,。/ conf.txt); 。它覆盖了您在命令行中设置的值,并且其中包含完整路径并且可以工作。在任何情况下,如果代码中有 System.setProperty ,则不会测试该命令行的效果。
For starters, remove System.setProperty("java.security.policy", "./conf.txt"); from you code. Its overriding the value you set at the command line, and that one had the full path in it and could have worked. In any case you are not testing the effect of that command line if you have System.setProperty in the code.
更多推荐
安全策略文件和jar
发布评论