3
votes

My Dev server my glassfish web app reports that it has a local of en_US. This is causing the dates to be displayed in US format. I want us use locale en_GB for the dates.

My Dev server is a virtual box configured as follows:

  • Ubuntu Ubuntu 12.04.2 LTS server
  • Oracle Java 1.7.0_11
  • GlassFish Server Open Source Edition 3.1.2.2 (build 5)
  • GlassFish is running using upstart
  • JavaServerFaces 1.2 Web app

Both the Host machine and the VM both return en_GB as the default OS locale

$ locale
LANG=en_GB.UTF-8
LANGUAGE=en_GB:en
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=en_GB.UTF-8

However in my web app when I write the locale to the log file, or when dates are displayed I can see that the locale is set to en_US.

                Locale locale = Locale.getDefault();
                log("Login.login_btn_action(): Default locale = " + locale.toString());

reports

Login.login_btn_action(): Default locale = en_US

To fix this I've tried the following (with no sucess):

1) In the Admin interface, selecting Domain and setting the locale to en_GB I can see that this setting appears in domain.xml in the first line:

2) Adding additional jvm-options in domain.xml to 'default-config' and 'server-config' to set user.language and user.country

    <jvm-options>-Duser.language=en</jvm-options>
    <jvm-options>-Duser.country=GB</jvm-options>

(Of course Each time I make a change I stop and start Glassfish)

Please can you suggest other options / settings to check / change to get my Java app to run with the native server locale?

1

1 Answers

0
votes

According to the Javadoc for Locale.getDefault(), you can change the default locale by using Locale.setDefault(Locale). Obviously, it isn't very nice to hard-code a locale in your app, so you could consider reading it from a config file or JVM option.