3

I need to add -Djava.security.policy=myPolicyFile so that my RMI jar would work. Or is there some other way to make that run?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
o_O
  • 516
  • 2
  • 8
  • 25

2 Answers2

4

If you're wanting to add the -D when someone launches your jar using java -jar, that's not possible because it's not possible to specify JVM options inside the jar:

Can I set Java max heap size for running from a jar file?

That said, if you're in control of the process, you could use java.security.Policy.setPolicy to manage the policy object yourself.

Community
  • 1
  • 1
Brett Kail
  • 33,593
  • 2
  • 85
  • 90
  • got this in my code: if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } should i add it there? – o_O May 23 '10 at 23:43
  • Do i have to use external policy file? Can i just put it in code? – o_O May 23 '10 at 23:57
  • No, there is no public API (that I'm aware of) for converting a policy file into a Policy object. You need to subclass java.security.Policy and properly implement getPermissions(CodeSource) to grant permissions to relevant code sources. – Brett Kail May 24 '10 at 01:25
1

You can take a look here on how to use policy files. If you are using netbeans or some other IDE, you should be able to add

-Djava.security.policy=myPolicyFile

as an option to your VM, which is usually found somewhere within the project's properties.

npinti
  • 51,780
  • 5
  • 72
  • 96
  • 1
    Yes, I know - got it in netbeans already but the problem is to get the same effect in jar. – o_O May 23 '10 at 23:42