This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 224526

Summary: Wrong output window encoding for maven project
Product: projects Reporter: Petr Adamek <xadamek2>
Component: MavenAssignee: Milos Kleint <mkleint>
Severity: normal CC: simpatico
Priority: P3    
Version: 7.3   
Hardware: PC   
OS: Windows 7   
Issue Type: DEFECT Exception Reporter:

Description Petr Adamek 2013-01-05 21:46:46 UTC
When you execute maven project that prints to System.out, some characters are displayed incorrectly in output window. 

Try to create new maven project with this class:

public class App {
    public static void main( String[] args ) {

When this class is executed, the output window displays this content:

Building mavenproject2 1.0-SNAPSHOT

[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory C:\Users\adamekp\tmp\mavenproject2\src\main\resources

Compiling 1 source file to C:\Users\adamekp\tmp\mavenproject2\target\classes

Total time: 0.799s
Finished at: Sat Jan 05 22:19:14 CET 2013
Final Memory: 7M/18M

This is specific just for maven projects in NetBeans 7.3 Beta 2. When you try to execute the same project in NetBeans 7.2, it works correctly. When you create the same class in standard java project (i.e. non maven), it also works. 

When you try to replace string "ěščřžýáíé!" with its escaped version "\u011b\u0161\u010d\u0159\u017e\u00fd\u00e1\u00ed\u00e9!", the problem is stil here, so it is not problem of source file encoding.
Comment 1 Petr Adamek 2013-01-06 09:46:25 UTC
Product Version: NetBeans IDE 7.3 Beta 2 (Build 201211062253)
Updates: NetBeans IDE is updated to version , NetBeans 7.3 Beta 2
Java: 1.7.0_09; Java HotSpot(TM) Client VM 23.5-b02
Runtime: Java(TM) SE Runtime Environment 1.7.0_09-b05
System: Windows 7 version 6.1 running on x86; Cp1252; en_US (nb)
User directory: C:\Users\adamekp\AppData\Roaming\NetBeans\7.3beta2
Cache directory: C:\Users\adamekp\AppData\Local\NetBeans\Cache\7.3beta2
Comment 2 Milos Kleint 2013-01-08 09:01:09 UTC
have you tried running on the cmd line? for me it returned more garbage..

experimentally reading the maven output stream with UTF-8 fixed the problem for me, so the most apparent way to fix it is to use the project encoding to read the stream. However that does backfire with some other encodings eg UTF-16. From what I know maven will use the platform encoding for output (as all it basically does is System.out.println()). then within the exec:exec goal the output of another spawned JVM is captured and printed to maven output (afaik just byte, not char operations are done there, but haven't verified in code). so if I got everything correctly, we end up with a stream containing 2 distinct encodings. 

so in my case Cp1250 is the system encoding while the project is in UTF-8.
In order to ensure that both the maven output and the application output share the same encoding, we would have to convince maven to use project's encoding for it's output. That's something I didn't succeed at yet. Only in such a case we can proceed and in the IDE, read the maven output with project encoding as well.

It worked for you in 7.2 because 7.2 has compile on save on by default and executes Run action with Ant behind the scenes which appears to pick UTF-8 blindly, which matches your project's encoding apparently. In 7.3 CoS is off by default.
Comment 3 Milos Kleint 2013-01-08 09:27:48 UTC
setting JAVA_TOOL_OPTIONS=-Dfile.encoding=<projectencoding> to the maven build partially works, most of the maven output is not garbage with UTF-16 is used but still some wrong characters are printed.. typically at the end of the output.
Comment 4 Milos Kleint 2013-08-21 13:10:15 UTC
I believe this doesn't have a solution on netbeans side, maven output needs to be consistent in terms of encoding. If parts are encoded differently, the output can come out garbled.
Comment 5 Milos Kleint 2013-12-20 14:50:11 UTC
setting -Dfile.encoding=<projectencoding> in nbactions.xml action mappings or in global Tools/Options appears to work fine now, I cannot reproduce the garbled output at the end with jdk 1.7+maven 3.0.5 and dev (pre 8.0) netbeans build. Encoding UTF-16 on a UTF-8 macosx.

almost the same results with windows-1252, only the unicode escapes worked for me then though. Could be an issue in copy&paste from browser to java main class I guess.

So now we set -Dfile.encoding on every maven build. triggered from the IDE. Let's see what happens when the beta comes out. If any problems surface I suppose we will need to hide it behind a system property or ui option.
Please test an upcoming dev build (build system will lost a comment with link eventually) or the upcoming beta to verify your issue is indeed fixed
Comment 6 Quality Engineering 2013-12-21 04:12:52 UTC
Integrated into 'main-silver', will be available in build *201312210002* on (upload may still be in progress)

User: Milos Kleint <>
Log: #224526 by default use the project's encoding (not IDE/system encoding) when executing builds. is the decision token here.
Comment 7 saamir 2014-10-25 09:45:33 UTC
Encountering the same issue when creating a Java Application project with maven but not with a regular Java Application project