jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes Change JVM locale before Start up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Change JVM locale before Start up" Watch "Change JVM locale before Start up" New topic

Change JVM locale before Start up

Mart?n L?pez

Joined: Apr 18, 2002
Posts: 3
Someone now how to change the default locale before a program start whitout modify the OS locale and the program, may be with a parameter.
Thanks in advance
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
Moving to Java In General( intermediate ) forum...

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Ashish Mahajan
Ranch Hand

Joined: Feb 19, 2003
Posts: 77
Hi mlopez,
Locale eng = Locale.US;

The best teams have no specialists, only general contributors with special skills
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
If you want to modify the locale before the program starts as you said, the solution is going to be OS-specific. The simplest solution is to modify the OS settings - e.g. on Windows XP go to Control Panel -> Regional and Language Options. If (as you said earlier) you don't want to do that either, there may be other undocumented solution. I found that on Windows XP if you do System.getProperties() one of the props is "user.country" - this is not a standards property required by the Java API, but that or something equivalent is probably on most operating systems. I found that if I invoke java with
java -Duser.country=CAN MyClass
and from MyClass.java call
my JVM now thinks it's in Canada. The OS locale remains unchanged.
Note that if you want a good cross-platform solution, you're really going to have to do it inside the program as Ashish shows. If you want, you can have the program read a properties file (or better yet, use Perferences) to detarmine what default locale the user wants.

"I'm not back." - Bill Harding, Twister
Mart?n L?pez

Joined: Apr 18, 2002
Posts: 3
Thanks guys.
Jim I', going to test this. I know that the best solution is a configuration file but I can't modify the program.
Ashish Mahajan
Ranch Hand

Joined: Feb 19, 2003
Posts: 77
Hi Martin,
Am assuming that u r developing standalone app. So as Jim said normally developer should store the user settings about the language. In 1.4 use Preferences API for 1.3 (Mac OS X) use xml (i know jdom, it's much faster)
Now when the app starts the first thing to do is to check the System's locale got by Locale.getDefault() if this language bundle is installed (the software may be having language pack updates) if installed then no probs one can go ahead. If the language bundle is not available then one should show the message to the user stating that and set the language to the softeware's default locale by Locale.setDefault(Locale)
Hope this helps
I agree. Here's the link: http://aspose.com/file-tools
subject: Change JVM locale before Start up
It's not a secret anymore!