Setting System properties from command-line

Code Sample:

public static void main(String[] args)
{
  String property = System.getProperty("my.text");
  System.out.println(property);
}

Execution:

java -Dmy.text="Hello World." -jar /home/user/application.jar

Note: With java -D you can set every property you like except the reserved ones, listed in [post id=2219]Java System Properties[/post].

You can set multiple properties with the following command:

java -Dmy.text="Hello World." -Dmy.ide="NetBeans IDE" -Dmy.browser="Mozilla Firefox" -jar /home/user/application.jar

Print Windows cmd output with Java

For some Java applications it might be important to access the console to print some information from a console command. That’s why I wrote a little program which reads the output from the Windows command-line interface (cmd) and shows it on the screen. Note: This script also works on a Linux shell!
Print Windows cmd output with Java weiterlesen