Monday, February 16, 2015

Set default properties for java on the commandline

If you need to add specific options to an existing java-environment, you can set those on the commandline. The java interpreter will pick up any options set for the environment-variable "_JAVA_OPTIONS" and add those to all other options that is is started with.
So if you have an existing start-script, just ensure that you set that environment-vaiable before you start it:

Here's an example for setting a default HTTP-proxy.

Windows:

#> set _JAVA_OPTIONS=-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8080
#> java -jar someprog.jar

Linux/MacOS:

#> export _JAVA_OPTIONS="-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8080"
#> java -jar someprog.jar