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
2010-05-23 23:28:22
Yes, I know - got it in netbeans already but the problem is to get the same effect in jar.
oO
2010-05-23 23:42:05
+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
2010-05-23 23:28:25
got this in my code:if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); }should i add it there?
oO
2010-05-23 23:43:44
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
2010-05-24 01:25:44