Saturday, February 19, 2011

Set Tomcat's Default Locale

If for whatever reason you want to set the locale in Tomcat you simply need to add two jvm arguments in the file found in the "bin" directory of the Tomcat installation. I was able to set the default locale for Tomcat to US/en on a Mac running Mac OS X Leopard with Tomcat 7.0.8 installed. These instructions should work for any *nix machine, but I can't guarantee it. If you're using windows, these instructions are probably also relevant, but instead you'd change catalina.bat.

Step 1: Open up the file with any text editor.

Step 2: Search for "JAVA_OPTS=" in the file and in particular locate the following lines of code:
if [ -z "$LOGGING_MANAGER" ]; then
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"

Step 3: At the end of the JAVA_OPTS definitions add "-Duser.language=en -Duser.region=US".
if [ -z "$LOGGING_MANAGER" ]; then
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Duser.language=en -Duser.region=US"
JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER -Duser.language=en -Duser.region=US"

Step 4: Save the file and restart Tomcat.

Piece of Cake!!


Nikitina Tetyana said...

Thank you!

RuBeNo said...

Thanks! Lines on Tomcat 7 in Windows are:

if not "%LOGGING_MANAGER%" == "" goto noJuliManager
set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager "-Duser.language=en"
set JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER% "-Duser.language=en"

Carlos G. said...

Excelent!, in my case, Tomcat 7 + Windows, in some place was configured spanish and with -Duser.language=en in the arguments, when start tomcat, the problem was solved