views:

183

answers:

2

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
A: 

What character encodings have you enabled in Terminal? I'm guessing it does not allow the encoding that javac is using. Look under Preferences > Encodings.

Sean Owen
I've got every encoding checked under 'Japanese', plus all of the UTF-* encodings.
Don Werve
+1  A: 

That's a well-known glitch of javac on OS X in Japanese environment. I had done a bit of Google searches myself, and I have found no fundamental cure. For now, the temporary solution I'm using is

javac -J-Dfile.encoding=utf8

which gives the error messages in Japanese encoded in UTF-8. Note that it's not -D, but -J-D. If you want the error messages in English, use

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

You can always make them into an alias, if you'd like:

 alias javac="LC_ALL=C javac -J-Dfile.encoding=utf8"
Yuji
That did the trick, thanks. 本当に助かりました。
Don Werve