security policy files and jar

佐手、 提交于 2019-12-07 07:28:56

问题


I have got RMI application, so I need to use policy files.

my policy file is simple (conf.txt):

grant {
    permission java.security.AllPermission;
};

I have no problems running my application from eclipse. I've added: -Djava.security.policy=conf.txt to the VM arguments.

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

I get the same result as without -Djava.security.policy option.

my code:

System.setProperty("java.security.policy", "./conf.txt");
...
if (System.getSecurityManager() == null) {
            System.setSecurityManager(new SecurityManager());
        }

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

回答1:


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.



来源:https://stackoverflow.com/questions/10163090/security-policy-files-and-jar

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