jar policy file

2020-07-11 10:24发布

问题:

I'm packaging my java application into a jar file but it only packages the class files. When I run the java program from the command line, usually this is what I have to do:

java -Djava.security.policy="..\java.policy" Server

My question is: is there a way to package a jar file and include this policy file? For instance, When the user wants to run the jar file, all he/she needs to do is type:

java -jar Server

回答1:

You can package the policy into the jar file and write some housekeeping code to create a security manager from the given policy file. The classloader does the hard work. Here is a sample.



标签: java jar