With Netbeans 9:
Product Version: Apache NetBeans IDE 9.0 (Build incubator-netbeans-release-334-on-20180708)
Java: 1.8.0_181; Java HotSpot(TM) 64-Bit Server VM 25.181-b13
Runtime: Java(TM) SE Runtime Environment 1.8.0_181-b13
System: Windows 10 version 10.0 running on amd64; UTF-8; en_EN (nb)
I want to be able to print:
String text = "你好!";
System.out.println(text);
The result is instead:
--- exec-maven-plugin:1.5.0:exec (default-cli) @ JavaApplication1 ---
???
I already added -J-Dfile.encoding=UTF-8
to the /etc/netbeans.conf
, added also to the VM options in configuration. Sources encoding option also set to UTF-8.
No problems with the past versions of Netbeans, here I found no way to display UTF-8 characters.
Which way can I do?
Updated on 9/8/21 to note that this solution does not work with NetBeans 12.x releases. See NetBeans 12 UTF-8 Chinese output with Maven projects
For a Maven application created in NetBeans 9.0 using Java 8 there are three actions needed to get Chinese characters to render correctly in the Output window, the first two of which you were already doing:
-J-Dfile.encoding=UTF-8
to the propertynetbeans_default_options
in file etc/netbeans.conf, and then restart NetBeans.System.setOut(new PrintStream(System.out, true, "UTF8"));
so that the print stream used when callingSystem.out.println()
supports UTF-8 encoding.It's also worth noting some changes that are not necessary:
file.encoding=UTF-8
in {project} > Properties > Run > VM Options.This is the code:
This is pom.xml:
This is the Output in NetBeans:
From the Output, note that:
System.setOut(new PrintStream(System.out, true, "UTF8"));
is called first.System.getProperty("file.encoding")
for the project returns "Cp1252" rather than "UTF-8":