How to check java timezone linux. Steps to set java timezone using tzupdater. update tzdata for openjdk rpm in RHEL or CentOS Linux. update tzdata-java rpm to update timezone for java in Linux. Check java timezone for openjdk using tzupdater in Linux. check openjdk timezone. Do I need to reboot after updating tzdata
In this article I will show you two methods to check and set java timezone (update tzdata for openJDK) with examples
Method 1: Update tzdata for openJDK using tzupdater
The first method to update tzdata for openJDK is usign TZUpdater tool. TZUpdater is a third party tool from Oracle which can be downloaded from official Oracle page.
What is TZUpdater?
The TimeZone updater tool or TZUpdater tool is provided to allow you to update installed Java Development Kit (JDK) and Java Runtime Environment (JRE) software with more recent timezone data, to accommodate daylight saving time (DST) changes in different countries. Oracle relies on the timezone data publicly available through IANA's Time Zone Database.
In RHEL or CentOS environment you will find tzdata rpm which controls the timezone applied at system level while tzdata-java
controls the timezone for java oriented applications such as openJDK, JRE etc
tzdata-java
can do the same change which is also supported and officially released by Red Hat.But still for the sake of this article I will share the steps which can be used to set java timezone in RHEL/CentOS/SLES or distributions having similar source code.
Install TZUpdater
Once you have downloaded the tzupdater archive, you can extract it under any location on your Linux host using the steps as shown below:
# unzip tzupdater-2_2_0.zip Archive: tzupdater-2_2_0.zip creating: tzupdater-2.2.0/ inflating: tzupdater-2.2.0/README inflating: tzupdater-2.2.0/tzupdater.jar
Check Java TimeZone
Before we update java timezone, we should check the existing tzdata bundle which is part of our OpenJDK rpm. Use the below syntax:
# cd /root/tzupdater-2.2.0/ # java -jar tzupdater.jar -V | grep version tzupdater version 2.2.0-b01 JRE tzdata version: tzdata2016i tzupdater tool would update with tzdata version: tzdata2019b
So currently my OpenJDK contains tzdata2016i which is really very old considering the latest available tzdata at the time of writing this article is 2019b.
Download tzdata archive
To update or set java timezone we must next manually download the tzdata archive. But if you just wish to use the latest available tzdata archive at IANA to update tzdata for OpenJDK then you need not download any archive. You just need an active internet connection and tzupdater tool will download the latest tzdata archive and install it in your openJDK binary.
To download different version of tzdata, you can check IANA page.
Set Java timezone using tzupdater
Now since my system is connected to internet and I wish to apply the latest available tzdata, I will just execute the below command to update or set java timezone:
[root@node1 tzupdater-2.2.0]# java -jar tzupdater.jar -l
Using https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz as source for tzdata bundle.
Failed: java.lang.Exception: Failed while parsing file '/tmp/tz.tmp/asia' on line 1865 'Rule Japan 1948 1951 - Sep Sat>=8 25:00 0 S'
java.lang.Exception: Failed while parsing file '/tmp/tz.tmp/asia' on line 1865 'Rule Japan 1948 1951 -Sep Sat>=8 25:00 0 S'
at tools.tzdb.TzdbZoneRulesCompiler.parseFile(TzdbZoneRulesCompiler.java:377)
at tools.tzdb.TzdbZoneRulesCompiler.compile(TzdbZoneRulesCompiler.java:191)
at tools.tzdb.TzdbZoneRulesCompiler.(TzdbZoneRulesCompiler.java:307)
at com.sun.tools.tzupdater.ExternalModule.compileToJSRBinary(ExternalModule.java:153)
at com.sun.tools.tzupdater.TimezoneUpdater.run(TimezoneUpdater.java:230)
at com.sun.tools.tzupdater.TimezoneUpdater.main(TimezoneUpdater.java:634)
Caused by: tools.tzdb.DateTimeException: Invalid value for SecondOfDay value: 90000
at tools.tzdb.ChronoField.checkValidValue(ChronoField.java:173)
at tools.tzdb.LocalTime.ofSecondOfDay(LocalTime.java:210)
at tools.tzdb.TzdbZoneRulesCompiler.parseMonthDayTime(TzdbZoneRulesCompiler.java:475)
at tools.tzdb.TzdbZoneRulesCompiler.parseRuleLine(TzdbZoneRulesCompiler.java:399)
at tools.tzdb.TzdbZoneRulesCompiler.parseFile(TzdbZoneRulesCompiler.java:354)
... 5 more
Here,
-l, --location Compile, test and update JRE timezone data from provided tzdata.tar.gz bundle e.g -l https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz Supported URL protocols : http://, https://, file:// If no URL link is provided, tool will use latest IANA tzdata bundle at: https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz
Looks like there is some problem with the "asia" timezone content which is part of tzdata2019b.
How to fix Failed while parsing file '/tmp/tz.tmp/asia'?
This has to be fixed by the development team of tzdata but for us to proceed we can use a workaround as also worked for me. I checked some backlogs and history and turns out all the tzdata released after 2018d contains this problem for asia timezone file. So we can take the asia
timezone file from tzdata 2018d and replace it in tzdata2019b
Download tzdata2018d from iana page
Extract it under a temporary location
# mkdir /tmp/tzdata2018d # cp tzddata2018d.tar.gz /tmp/tzdata2018d # cd /tmp/tzdata2018d # tar -xzvf tzddata2018d.tar.gz
Repeat the same steps for tzdata2019b
# mkdir /tmp/tzdata2019b # cp tzddata2019b.tar.gz /tmp/tzdata2018d # cd /tmp/tzdata2019b # tar -xzvf tzddata2019b.tar.gz
Next replace the asia
timezone from from 2018d to 2019b
node1:/tmp/tzdata2018d # cp asia ../tzdata2019b/asia node1:/tmp/tzdata2018d # cd ../tzdata2019b/
Next re-create the archive for 2019b with the latest changes
node1:/tmp/tzdata2019b # tar -czvf ../tzdata2019b.tar.gz *
Now let us re-try to set java timezone using tzupdater tool
node1:/tmp/tzupdater-2.2.0 # java -jar tzupdater.jar -l file:///tmp/tzdata2019b.tar.gz
So our workaround worked and we are have successfully set java timezone.
Using file:///tmp/tzdata2019b.tar.gz
as source for tzdata bundle.
node1:/tmp/tzupdater-2.2.0 # java -jar tzupdater.jar -V tzupdater version 2.2.0-b01 JRE tzdata version: tzdata2019b tzupdater tool would update with tzdata version: tzdata2019b
Restart your java applications to activate the new timezone related changes
Method 2: Update tzdata for openJDK using tzdata-java
For OracleJDK in Red Hat/CentOS environment you can alternatively use tzdata-java
rpm which will also internally set java timezone without any hassle.
timezone-java
but this has no impact on tzdata version which is part of OpenJDK so you will have to use tzupdaterCurrently my system is running with 2018e version of tzdata rpm as you can see below:
# rpm -qa | grep tzdata tzdata-java-2018e-3.el7.noarch tzdata-2018e-3.el7.noarch
Also if we check java version using tzupdater, my OpenJDK has 2018e version of tzdata
[root@node1 tzupdater-2.2.0]# java -jar tzupdater.jar -V
tzupdater version 2.2.0-b01
JRE tzdata version: tzdata2018e
tzupdater tool would update with tzdata version: tzdata2019b
Next we will update tzdata rpm to 2019a by manually downloading the rpm from IANA database
[root@node1 tzupdater-2.2.0]# rpm -Uvh /root/tzdata-2019a-1.el7.noarch.rpm warning: /root/tzdata-2019a-1.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] Updating / installing... 1:tzdata-2019a-1.el7 ################################# [ 50%] Cleaning up / removing... 2:tzdata-2018e-3.el7 ################################# [100%]
And re-verify the tzdata version for OpenJDK, which remains unchanged to we know tzdata has no impact on tzdata of OracleJDk
[root@node1 tzupdater-2.2.0]# java -jar tzupdater.jar -V
tzupdater version 2.2.0-b01
JRE tzdata version: tzdata2018e
tzupdater tool would update with tzdata version: tzdata2019b
Next we will update tzdata-java rpm to 2019a
[root@node1 tzupdater-2.2.0]# rpm -Uvh /root/tzdata-java-2019a-1.el7.noarch.rpm warning: /root/tzdata-java-2019a-1.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] Updating / installing... 1:tzdata-java-2019a-1.el7 ################################# [ 50%] Cleaning up / removing... 2:tzdata-java-2018e-3.el7 ################################# [100%]
Re-verify the tzdata for OracleJDK, as you see now our java for OpenJDK also contains tzdata2019a
[root@node1 tzupdater-2.2.0]# java -jar tzupdater.jar -V
tzupdater version 2.2.0-b01
JRE tzdata version: tzdata2019a
tzupdater tool would update with tzdata version: tzdata2019b
Restart your java applications to activate the new timezone related changes
Lastly I hope the steps from the article to update or set java timezone (update tzdata for openJDK) using tzupdater on Linux was helpful. So, let me know your suggestions and feedback using the comment section.