Search code examples
javasecurityrmi

security policy files and jar


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

Solution

  • 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.