views:

55

answers:

2

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?

A: 

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
Yes, I know - got it in netbeans already but the problem is to get the same effect in jar.
oO
+3  A: 

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:

http://stackoverflow.com/questions/1018217/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.

bkail
got this in my code:if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); }should i add it there?
oO
Do i have to use external policy file? Can i just put it in code?
oO
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.
bkail