How do I set the default locale via System properties?
Author: Deron Eriksson
Description: This Java tutorial describes how to set the default locale via system properties.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0)
In another tutorial, we saw how we could use the Locale.setDefault() method to set the default locale at runtime. If we examine the System properties, we can see the "user.language" property which is responsible for the default language and the "user.country" property which is responsible for the default country. My "user.language" is set to "en" and "user.country" is set to "US".
Since the default country and default language for the locale are System properties, they can be set at start-up via -D VM arguments, such as the following arguments that set the default language to Swedish and the default country to Sweden.
It should be noted that the "user.language" and "user.country" values need to be passed as VM Arguments at startup and NOT set using System.setProperty() at runtime, since System.setProperty() will not influence the default locale that is already in memory. If you need to change the default locale during runtime, use Locale.setDefault();
// THIS WON'T WORK - IF YOU NEED TO SET DEFAULT LOCALE AT RUNTIME, USE Locale.setDefault() System.setProperty("user.language", "sv"); System.setProperty("user.country", "SE");