we are migrating a Java build task from one server to another (Linux). When starting the ant job it gives following error:
Date of 10/21/2024 05:31 p.m. Cannot be parsed correctly. It should be in 'MM/dd/yyyy hh:mm a' format.
Strange as the same job is running for years without eny errors on the 'old' server. Both are running Ant 1.10.12 and Java 21
The error is caused by the line in the fileset:
<date datetime="${1_day_ago}" when="before"/>
in this task:
<target name="clean-files" depends="init">
<!-- Define which bu directories should be archived ( = older than 1 day) -->
<tstamp>
<format property="1_day_ago" pattern="MM/dd/yyyy hh:mm aa" offset="-10" unit="day"/>
</tstamp>
<delete includeemptydirs="false" verbose="true">
<fileset dir="${basedir}/tmp/" includes="*.properties">
<date datetime="${1_day_ago}" when="before"/>
</fileset>
</delete>
</target>
As identical code is running on both server we have no idea what is causing this.
Specs 'old' server (jdk-21-oracle-x64):
Linux betrust21 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3.1 (2019-02-19) x86_64
java version "21.0.3" 2024-04-16 LTS
Java(TM) SE Runtime Environment (build 21.0.3+7-LTS-152)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.3+7-LTS-152, mixed mode, sharing)
New server (openJdk):
Welcome to Ubuntu 22.04.5 LTS (GNU/Linux 5.15.0-122-generic x86_64)
openjdk version "21.0.4" 2024-07-16
OpenJDK Runtime Environment (build 21.0.4+7-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 21.0.4+7-Ubuntu-1ubuntu222.04, mixed mode, sharing)
We changed the pattern in:
<format property="1_day_ago" pattern="MM/dd/yyyy hh:mm aa" offset="-10" unit="day"/>
in various ways but to no avail. Always the same error. Removing the pattern is not possible as required.
Any suggestions ?
So to answer my own question based on the comments:
The problem was that the 'old' server has a locale LANG=en_US.UTF-8 bu the new server has locale LANG=nl_NL.UTF-8 (on Linux level). So I added the locale:
<format property="1_day_ago" pattern="MM/dd/yyyy hh:mm a" locale="en,US" offset="-1" unit="day" />
and now it is working as expected.
Note also the correct pattern is 'MM/dd/yyyy hh:mm a' and not 'MM/dd/yyyy hh:mm aa'.