I am debugging a problem in a large system. I was able to locate the problem in a rather basic java feature – the application is started with the -D option to specify some system properties. During run-time though, said properties are not set and their values are null.
Trying to reproduce the issue I created the following very simple application:
public static void main(String[] args) {
String propName = "sysprop";
String propValue = System.getProperty(propName);
System.out.println(propName + "=" + propValue);
}
I start the application with the following command line and to my surprise got the same result:
java -cp javaapplication8.jar javaapplication8.JavaApplication8
-Dsysprop="some value"sysprop=null
Apparently I am missing something obvious (or lack some basic knowledge) but what is it?
Thank you.
You’re specifying
-Dafter the classname, so it’s being treated as a regular command line argument to be passed on to the application itself. You would see that if you printed out the values inargs.Run the app like this instead:
All arguments which are meant to apply to the environment rather than the application should come before the classname. If you run just
java, you’ll see usage help like this: