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 catalina.sh 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 catalina.sh 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"
else
JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
fi

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"
else
JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER -Duser.language=en -Duser.region=US"
fi

Step 4: Save the file and restart Tomcat.

Piece of Cake!!

3 comments:

Unknown said...

Thank you!

RuBeNo said...

Thanks! Lines on Tomcat 7 in Windows are:
:noJuliConfig
set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%

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

Carlos G. said...

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