How do I run javac from cmd to correctly display Cyrillic characters in the file name when displaying compilation results?


Compiling a java file with a Cyrillic name from the command line. When errors are output, hieroglyphs are output. How can it be solved?

Author: titov_andrei, 2015-12-10

2 answers

In the console (cmd.exe), before calling the compiler, switch the code page with the command

chcp 1251

It is enough to do this once every time you start the console. javac in Russian-language Windows, it outputs messages in the cp1251 encoding, and the console uses cp866.

Example:

E:\>chcp 1251
Текущая кодовая страница: 1251

E:\>javac -encoding utf8 ./Проверка.java ./Проверка2.java
.\Проверка2.java:3: error: cannot find symbol
                System.out.pri("Работает! 2");
                          ^
  symbol:   method pri(String)
  location: variable out of type PrintStream
1 error

The key -encoding utf8 indicates the encoding of the source file.

You can do the opposite, and explain to javac that it should output the text in the desired encoding, using the key -J-Dfile.encoding=cp866:

E:\>chcp 866
Текущая кодовая страница: 866

E:\>javac -J-Dfile.encoding=cp866 -encoding utf8 ./Проверка.java ./Проверка2.java
.\Проверка2.java:3: error: cannot find symbol
                System.out.pri("Работает! 2");
                          ^
  symbol:   method pri(String)
  location: variable out of type PrintStream
1 error

To output in utf-8, you need to enable the code page 65001 and set the encoding utf8 to the compiler.

To set the output encoding for all java calls, you can use the environment variable JAVA_TOOL_OPTIONS.

 8
Author: zRrr, 2015-12-10 23:45:39

Somehow it can be solved. Translate all file names to Latin letters.

No book, reference, or documentation recommends using the Cyrillic alphabet in the names of classes and variables.

 1
Author: LEQADA, 2015-12-10 19:37:22