Freewind
Freewind

Reputation: 198238

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 ?

Upvotes: 15

Views: 4033

Answers (1)

SnakE
SnakE

Reputation: 2571

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.

Upvotes: 8

Related Questions