3

I've got my computer set up in Japanese (hey, it's good language practice), and everything is all fine and dandy... except javac. It displays localized error messages out to the console, but they're in Shift-JIS, not UTF8:

$ javac this-file-doesnt-exist.java
javac: ?t?@?C??????????܂???: this-file-doesnt-exist.java
?g????: javac <options> <source files>
?g?p?\?ȃI?v?V?????̃??X?g?ɂ??ẮA-help ???g?p???܂

If I pipe the output through nkf -w, it's readable, but that's not really much of a solution:

$ javac this-file-doesnt-exist.java 2>&1 | nkf -w
javac: ファイルが見つかりません: this-file-doesnt-exist.java
使い方: javac <options> <source files>
使用可能なオプションのリストについては、-help を使用します

Everything else works fine (with UTF8) from the command-line; I can type filenames in Japanese, tab-completion works fine, vi can edit UTF-8 files, etc. Although java itself spits out all its messages in English (which is fine).

Here's the relevant bits of my environment:

LC_CTYPE=UTF-8
LANG=ja_JP.UTF-8

From what it looks like, javac isn't picking up the encoding properly, and java isn't picking up the language at all. I've tried -Dfile.encoding=utf8 as well, but that does nada, and documentation on the localization of the JVM toolchain is pretty nonexistent, at least from Google.

Addendum:

Macports OpenJDK6 has better behavior:

$ /opt/local//share/java/openjdk6_bootstrap/bin/javac this-file-doesnt-exist.java 
javac: file not found: this-file-doesnt-exist.java
Usage: javac <options> <source files>
use -help for a list of possible options
4

2 回答 2

1

这是日本环境中 OS X 上众所周知的 javac 故障。我自己做了一些谷歌搜索,我没有找到根本的治疗方法。目前,我使用的临时解决方案是

javac -J-Dfile.encoding=utf8

它给出了以 UTF-8 编码的日语错误消息。请注意,它不是-D,而是-J-D。如果您想要英文的错误消息,请使用

 LC_ALL=C javac -J-Dfile.encoding=utf8

如果您愿意,您可以随时将它们设为别名:

 alias javac="LC_ALL=C javac -J-Dfile.encoding=utf8"
于 2010-03-15T22:26:35.557 回答
0

您在终端中启用了哪些字符编码?我猜它不允许 javac 使用的编码。查看首选项 > 编码。

于 2010-03-15T09:34:53.663 回答