7

According to Oracle, the only way to set system properties is through command line -D parameters like that :

java -Dmy.prop=value com.package.MyClass

Is it really the only way ? Isn't it possible to create some system.properties file that will contain all these properties, and that would be automagically read when the JVM starts ?

I precise I can have no use of the System.setProperty(String,String) function.[1]

Setting this file through a command line parameter would be fine as well :

java -Fsystem.properties com.package.MyClass

I have searched where I know (and found there is a way with IBM's JVM), but I'm still empty-handed...

[1] : The goal is to set the default Charset, and this is primarily done through the file.encoding property, but only at the VM startup phase. Setting this property in runtime doesn't change the default Charset, and there is also no way to change it 'programmatically'.

Kara
  • 6,115
  • 16
  • 50
  • 57
glatapoui
  • 363
  • 4
  • 14
  • 3
    Unfortunately, your end goal of setting the default encoding via `file.encoding` is impossible (or at least, [not supported or without unintended side-effects](http://bugs.sun.com/view_bug.do?bug_id=4163515).) Not that this isn't a good question in the general case. – McDowell Sep 09 '11 at 20:17
  • OK, this is a pretty old restriction/bug. The problem by our side is that we have multiple starters and we didn't want to set this property through all of them. But in the end this is what we have done, since we were lacking a more general approach. It would have been also really nice to have the opportunity to pass this argument (`-Dfile.encoding`) as well as others through a file but if it is not possible, well... Thank you nevertheless for your answer ! – glatapoui Sep 26 '11 at 15:37
  • Possible duplicate of [How to set a java system property so that it is effective whenever I start JVM without adding it to the command line arguments](http://stackoverflow.com/questions/12577437/how-to-set-a-java-system-property-so-that-it-is-effective-whenever-i-start-jvm-w) – Paul Sweatte Oct 14 '16 at 15:01
  • Thanks Paul, but I would rather not mess with the default VM arguments since it could impact other applications. – glatapoui Mar 06 '17 at 22:37

0 Answers0