如何让Java输出英语错误而不是其他语言? [英] How to let java output English errors instead of other languages?

查看:237
本文介绍了如何让Java输出英语错误而不是其他语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统是中文,并且当我的java程序中发生错误时,它可能会输出不可读的非英语错误消息:

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, 系统脮也禄碌陆指露

或:

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

是否可以让Java始终输出英语错误消息?

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

推荐答案

答案有两个部分.

  1. Java根据默认语言环境显示错误消息.有三个定义默认语言环境的系统属性:user.languageuser.countryuser.variant.如果您有权访问Java VM命令行,则可以使用-D命令行开关设置这些属性.例如.这足以将Java切换为通用英语:

  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

  • 您可以定义JAVA_TOOL_OPTIONS环境变量,并在此处指定选项.在这种环境中启动的所有JVM都会选择这些选项,就像在命令行中一样.

  • 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.

    这篇关于如何让Java输出英语错误而不是其他语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆