1

I developed a swing java application that connects to Oracle (installed on win).
When it tries to connect to DB get exception as "Locale not recognized".
To solve it, I used environment variable "JAVA_TOOLS_OPTIONS" as bellow.

set JAVA_TOOL_OPTIONS=-Duser.language=en -Duser.region=us -Duser.country=us 

and my app works well.
If I want to send my to clients, it would be a problem. I tried to include settings in my app as adding bellow lines to main class

System.setProperty("user.language", "en");  
System.setProperty("user.region", "us");  
System.setProperty("user.country", "us");

but doesn't affected and I get exception again.
How can I do that?
Thanks

Moh Tarvirdi
  • 685
  • 1
  • 13
  • 25

2 Answers2

2

Maybe this helps: http://www.oracle.com/technetwork/java/javase/envvars-138887.html#gbmsy To me it looks like you cannot set these options using System.setProperty(), because the Java Tool options have to be set before running your application. I would suggest one of these

  • write a shell script (for *NIX/Linux) similar to this: JAVA_TOOL_OPTIONS="-Duser.language=en -Duser.region=us -Duser.country=us" java -jar [your application]. I don't know if this would also work for windows
  • create a jar to launch your application with the correct environment variables, see e.g. this question and tell your clients to "simply launch the launcher"
Community
  • 1
  • 1
user3001
  • 3,437
  • 5
  • 28
  • 54
1

It possible you're not making those calls early enough, and the classes that use them have already been loaded and initialized themselves.

A good test/quick fix would be to make a separate Main class that only makes those calls, then calls the class you are currently using to start your app.

You might even have to call those in a static initializer (not in main), because once you execute main, all the classes it references will be loaded first.

You could also use reflection to load and execute your class from Main, that's kind of messy and probably not required.

Ted Bigham
  • 4,237
  • 1
  • 26
  • 31
  • I added just first line of "public static void main(String[] args)" but didn't work! – Moh Tarvirdi Mar 01 '14 at 10:45
  • That's unfortunate. It might require a static initializer or reflection, but since it looks like Locale.setDefault is working for you, it might not be worth messing around to find out. – Ted Bigham Mar 01 '14 at 10:48