Wednesday 2 March 2016

System Properties

Although it is possible to read host environment variables from Java, it is discouraged for application configuration. Instead, Java allows any number of system property values to be passed to the application when the VM is started. System properties are simply name-value string pairs that are available to the application through the static Sys tem.getProperty() method. You can use these properties as a more structured and portable alternative to command-line arguments and environment variables for providing general configuration information to your application at startup. Each system property is passed to the interpreter on the command line using the -D option followed by name=value. For example:

 % java -Dstreet=sesame -Dscene=alley animals.birds.BigBird  
The value of the street property is then accessible this way:
 String street = System.getProperty("street");  
An application can get its configuration in myriad other ways, including via files or network configuration at runtime.

0 comments:

Post a Comment