Freitag, Januar 06, 2012

How to force Tomcat to run with the correct Locale and Timezone

After I started Tomcat on our Production Server and deployed our Web-Application, we noticed that the time we got from java.util.Date was six hours too early. Seems like Tomcat's Locale/Timezone was somehow set to US insteadof DE.

After some Googling we found out that we had to tell Tomcat on startup which Locale and Timezone to use: 

-Duser.timezone=Europe/Berlin
-Duser.country=DE
-Duser.language=de

Sounds easy and worked great if we started Tomcat with a batch-file. However, Tomcat is running as a service, so somehow we had to get those Parameters into the service. Deinstallation (and then Reinstallation with the correct parameters) of the service was not an option because it seemed we had to reboot the machine then and we wanted to avoid that.

The solution for us was to place the Parameters for the service directly in the Windows Registry and then just restart the service.

The Registry-Key that contains the Startup-Parameters is:
HKEY_LOCAL_MACHINE/Software/Apache Software Foundation/Procrun 2.0/Tomcat6Prod/Parameters/Java/Options where "Tomcat6Prod" is the name of our service. The type of the key is a Multiline String (REG_MULTI_SZ) so you can put in one line per Parameter:

-Dcatalina.base=<path>
-Dmoreparameters...
-Duser.timezone=Europe/Berlin
-Duser.country=DE
-Duser.language=de

Keine Kommentare: