This week's book giveaway is in the Flex forum. We're giving away four copies of Flex 4 in Action and have Tariq Ahmed, Dan Orlando, John C. Bland II & Joel Hooks on-line! See this thread for details.
-Dproperty=value Set a system property value. If value is a string that contains spaces, you must enclose the string in double quotes: java -Dfoo="some string" SomeClass
My question is: How can I access this property value in the code. Does someone have an example?
A JVM runs with a number of system properties. You can configure system properties by using the -D option, pronounced with an upper case 'D'
All you have to do i suse the -D flag, and provide the system prperty name immediately following the D, and equals sign, and then the value to be assigned to the property. For example, to set the file.encoding property of the Java runtime to utf-8, you could set the following property:
java -Dfile.encoding=utf-8
You can then grab the value programatically as follows:
System.getProperty("file.encoding"); /*this method is overloaded, as per previous post*/
Peter Heide wrote:One of the SCJA Exam Objectives is:
demonstrate the proper use of the "java" command including the command-line option -D
The java jdk documentation specifies:
-Dproperty=value
Set a system property value. If value is a string that contains spaces, you must enclose the string in double quotes:
java -Dfoo="some string" SomeClass
My question is: How can I access this property value in the code. Does someone have an example?
Can someone let me know how I and specify multiple key/value pairs?
Can someone let me know how I and specify multiple key/value pairs?
Thanks,
Use several -D arguments
Basically, it's text. You can also do something like :
then you need to analyze the string key:val,key2:val2,key3:val3 to split it and get the key:val strings.
And you can split these again to get key and val.
String tokenizer is your friend Or regexp :-)