43

There was a change in Java 1.7 in the way the default Locale is get from the OS. There are methods of restoring the old behaviour e.g. by setting the flag -Dsun.locale.formatasdefault=true when starting a JVM instance.

I would like to set this flag permanently so that I don't have to specify it in command line arguments each time when I start a JVM instance. Is there a file or any other possibility to change the default settings for JVM? Something like the Eclipse.ini file but for the JVM itself?

1
  • I don't believe there is, but you can create a Boot class which automatically executes your program (with the "true" main method in another class), with the desired command line arguments present.
    – FThompson
    Sep 25, 2012 at 6:49

1 Answer 1

59

You can set set environment variable JAVA_TOOL_OPTIONS in your OS. All Java tools (java, javac, ..) will pick this variable up and use it. So you could e.g. use

SET JAVA_TOOL_OPTIONS=-Dsun.locale.formatasdefault=true

I use this to force a specific locale for each JVM.

But this only works if your application is started through the Java tools. If it is e.g. started from a C program that calls the jvm DLL this won't be used.

Edit: I just tested it, and it seems JAVA_TOOLS_OPTIONS is also picked up when the DLLs are started (verified with a Swing application that uses WinRun4J as a launcher)

See: http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/envvars.html

5
  • 4
    We use _JAVA_OPTIONS and that seems to work for use, don't know if this will work for calling through the DLL though, I doubt it. Sep 25, 2012 at 7:11
  • @MadProgrammer: interesting. I didn't know about _JAVA_OPTIONS
    – user330315
    Sep 25, 2012 at 7:20
  • @a_horse_with_no_name No, I didn't know about it until about a week ago either Sep 25, 2012 at 7:23
  • Information about _JAVA_OPTIONS
    – Vadzim
    Oct 27, 2015 at 20:21
  • Can anyone clear it up for me if I want to add a system property xyz-abc.dest="path", Do I have to prepend it with "-D" ? Jun 15, 2018 at 9:59

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.