I am using a simple way to implement a custom policy file, which works fine when implemented via cmd.
List < String > paramsExecute = new ArrayList < String > ();
paramsExecute.add("java");
paramsExecute.add("-cp");
paramsExecute.add(Path);
paramsExecute.add("dummy."+packageName);
paramsExecute.add("-Djava.security.manager");
paramsExecute.add("-Djava.security.policy=C:\\full\\path\\MyPolicyFile.policy");
ProcessBuilder builder = new ProcessBuilder(paramsExecute);
I have checked the classPath.No Exception is thrown, but the policy file is not implemented, where is the Bug?
Arguments before the main class name are interpreted by the JVM. Arguments after the main class name are passed to the program - the JVM doesn't look at them.
This order of parameters should work - note that all the options are before the main class name:
List < String > paramsExecute = new ArrayList < String > ();
paramsExecute.add("java");
paramsExecute.add("-cp");
paramsExecute.add(Path);
paramsExecute.add("-Djava.security.manager");
paramsExecute.add("-Djava.security.policy=C:\\full\\path\\MyPolicyFile.policy");
paramsExecute.add("dummy."+packageName);