The version of Java is printed below:
$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
When passing a property like so:
java -Dmy.property=value -jar my.jar
..it fails to resolve in the code:
System.getProperty("my.property") // => null
However using an underscore in place of the dot works fine:
// CLI
java -Dmy_property=value -jar my.jar
// In the code:
System.getProperty("my_property") // => "value"
Isn't this non-standard behaviour?
In case it's relevant, the JAR is being built via Maven and the maven-assembly-plugin
is being used to bundle dependencies into the JAR.
Initially I was using the improper format java -jar my.jar -Dmy.prop=value
rather than the correct java -Dmy.prop=value -jar my.jar
. But I realised this early on and amended my parameter ordering.
However, it turns out when editing the monolithic chain of commands I was editing (with this java -jar
command in-line amongst them) I mistakenly created another incorrect command structure: java -jar -Dmy.prop=value my.jar
.
The first time I used underscores the command was rewritten, thus inadvertently fixing this latter incorrect parameter structure.
So the moral of the story is: ensure you have -jar my.jar
right at the end of your java
command. Always!
Java supports dots in property names when you set them like that.
A couple of possible explanations:
The actual command being executed is different to that. Maybe there's a bug in your launch script or something. (Try using "set -x" to get the shell to tell you what the actual command options are.)
Some other part of your application is unsetting that particular property before the call to getProperty
you are looking at.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.