Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let java output English errors instead of other languages?

My system is Chinese, and when there is an error occurs in my java program, it may output non-English error messages which is unreadable:

Caused by: java.io.IOException: CreateProcess error=2, 系统脮也禄碌陆指露

or:

IOException occured : Cannot run program "cmd /C tsc hello.ts": 
CreateProcess error=2, ϵͳÕҲ»µ½ָ¶

Is it possible to let java always output English error messages ?

like image 847
Freewind Avatar asked Jan 26 '13 08:01

Freewind


People also ask

How can I change the language of Java?

setDefault(java. util. Locale. ENGLISH); JFileChooser chooser = new JFileChooser(); chooser.

What is localization Java?

Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text.

Should error messages be translated?

Depends on the app. A highly technical application that will be used by people that understand English and the target language, you might be OK with English error messages. If it's a message that will be seen by the end user, it should be translated.


1 Answers

There are two parts to the answer.

  1. Java displays error messages based on the default locale. There are three system properties which define the default locale: user.language, user.country and user.variant. If you have access to your Java VM command line you can set these properties using the -D command line switch. E.g. this is enough to switch Java to generic English:

    java -Duser.language=en com.my.Class
    
  2. You can define a JAVA_TOOL_OPTIONS environment variable and specify your options there. Any JVM starting in such environment will pick these options up as if they were on the command line.

like image 122
SnakE Avatar answered Oct 02 '22 15:10

SnakE