[ Back | Previous | Next ]

How to add a policy at Runtime?

Package:
java.security.*
Product:
JDK
Release:
1.1.x
Related Links:
General
General
Comment:
It is also possible to specify an additional or a different policy file when invoking
          execution of an application. This can be done via the "-Djava.security.policy"
          command line argument, which sets the value of the java.security.policy
          property. For example, if you use 

              java -Djava.security.manager -Djava.security.policy=someURL SomeApp

          where someURL is a URL specifying the location of a policy file, then the
          specified policy file will be loaded in addition to all the policy files that are specified
          in the security properties file. 

          Notes: 

               The URL can be any regular URL or simply the name of a policy file in the
               current directory, as in 

                   java -Djava.security.manager -Djava.security.policy=mypolicy WriteFile

               The "-Djava.security.manager" argument ensures that the default security
               manager is installed, and thus the application is subject to policy checks. It
               is not required if the application SomeApp installs a security manager. 

          If you use 

             java -Djava.security.manager -Djava.security.policy==someURL SomeApp

          (note the double equals) then just the specified policy file will be used; all the
          ones indicated in the security properties file will be ignored. 

          If you want to pass a policy file to the appletviewer, then use a
          "-J-Djava.security.policy" argument as follows: 

              appletviewer -J-Djava.security.policy=someURL myApplet

          Please note: The "-Djava.security.policy" policy file value will be ignored (for both
          java and appletviewer commands) if the "policy.allowSystemProperty"
          property in the security properties file is set to false. The default is true.