Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override System Property in Java (without code)

Is it possible to override system property (timezone etc.) in Java using predefined properties file for all Java applications?

I couldn't find such a file in my Windows 7 64bit OS.

Java version is 1.7.0_03 (JDK 64 bit)

Java "-Duser.timezone parameter cannot be used because it is a compiled exe file (does not accept java parameter). And we use those java applications as end users. We have not developed them. So setting timezone by programming is not an option.

Java uses different timezone other than systems'. I think there are some bugs with Java with Windows 7.

http://oraclesoon.blogspot.com/2010/04/windows-7-and-java-jdk-16-timezone.html

like image 521
Turkdogan Tasdelen Avatar asked Mar 23 '12 10:03

Turkdogan Tasdelen


People also ask

Can we override properties in Java?

You cannot "override" fields, because only methods can have overrides (and they are not allowed to be static or private for that).

How do I unset a system property in Java?

System. clearProperty(String key) method enables you to remove a system property. The key must not be an empty string or a null value because it will cause the method to throw an IllegalArgumentException or a NullPointerException .


1 Answers

The _JAVA_OPTIONS envionment variable allows you to set commandline flags when java is run.

The following propagated into java for me (on OSX):
export _JAVA_OPTIONS='-Duser.timezone=Europe/Copenhagen'

It is hard to know if it will work with your .exe setup also but give it a try.

You may need to restart after changing environment variables on windows.

like image 86
Johannes Avatar answered Oct 30 '22 16:10

Johannes