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 244164 - Messy code in use UTF8
Summary: Messy code in use UTF8
Status: NEW
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 8.0
Hardware: PC Windows 7
: P3 normal with 2 votes (vote)
Assignee: Tomas Stupka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-29 09:43 UTC by runshine
Modified: 2016-07-20 05:25 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Demo maven project of messycode,remember add -Dfile.encoding=UTF-8 to conf (2.43 KB, application/x-zip-compressed)
2014-04-29 09:43 UTC, runshine
Details

Note You need to log in before you can comment on or make changes to this bug.
Description runshine 2014-04-29 09:43:42 UTC
Created attachment 147000 [details]
Demo maven project of messycode,remember add -Dfile.encoding=UTF-8 to conf

I was add “-Duser.language=zh -Duser.country=CN -Dfile.encoding=UTF-8” to netbeans.conf

In maven project,when I use build,run,install and so on,if there's non-ascii character out to console,it will be display messy code.Like "�й���ϸ��Ϣ, ��ʹ�� -Xlint:unchecked ���±��롣"
It looks like Netbeans-Maven deem the enviroment is GBK.

Some cases ,"Run", org.codehaus.mojo:exec-maven-plugin:exec,i can add "exec.args=-Dfile.encoding=UTF-8" to resolve the problem. But it only resolve partial.
Comment 1 Milos Kleint 2014-04-29 10:48:07 UTC
please see issue 224526, comment 5 - https://netbeans.org/bugzilla/show_bug.cgi?id=224526#c5

setting the encoding for the IDE's JVM is likely irrelevant, it can be different for each project and apparently is not picked up automatically by java.lang.Runtime.exec() 

most likely a duplicate of issue 224526
Comment 2 runshine 2014-04-30 02:43:02 UTC
(In reply to Milos Kleint from comment #1)
> please see issue 224526, comment 5 -
> https://netbeans.org/bugzilla/show_bug.cgi?id=224526#c5
> 
> setting the encoding for the IDE's JVM is likely irrelevant, it can be
> different for each project and apparently is not picked up automatically by
> java.lang.Runtime.exec() 
> 
> most likely a duplicate of issue 224526

It's not only when execute,but also when compile and other action.
Maybe maven-plugin cant't sense parameter of netbeans.conf 

example
public class Main {
    public static void main(String[] args) {
        sun.misc.BASE64Decoder l = new sun.misc.BASE64Decoder();
        System.out.println("\u4f60\u597d");
        System.out.println("你好");
    }
}

############################################################################
use exec:exec without "exec.args=-Dfile.encoding=UTF-8"

cd F:\NBProject\maven-messycode; JAVA_HOME=E:\\Java\\jdk1.7.0_51 cmd /c "\"\"E:\\Java\\NetBeans 8.0\\java\\maven\\bin\\mvn.bat\" -Dexec.args=\"-classpath %classpath com.runshine.maven.messycode.Main\" -Dexec.executable=E:\\Java\\jdk1.7.0_51\\bin\\java.exe -DskipTests=true -DnetbeansProjectMappings= -Dmaven.ext.class.path=\"E:\\Java\\NetBeans 8.0\\java\\maven-nblib\\netbeans-eventspy.jar\" org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
                                                                        
------------------------------------------------------------------------
Building maven-messycode 1.0.0
------------------------------------------------------------------------

--- exec-maven-plugin:1.2.1:exec (default-cli) @ maven-messycode ---
���
���
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 0.690s
Finished at: Wed Apr 30 10:13:16 CST 2014
Final Memory: 5M/154M
------------------------------------------------------------------------

############################################################################
use exec:exec with "exec.args=-Dfile.encoding=UTF-8"

cd F:\NBProject\maven-messycode; JAVA_HOME=E:\\Java\\jdk1.7.0_51 cmd /c "\"\"E:\\Java\\NetBeans 8.0\\java\\maven\\bin\\mvn.bat\" -Dexec.args=\"-Dfile.encoding=UTF-8 -classpath %classpath com.runshine.maven.messycode.Main\" -Dexec.executable=E:\\Java\\jdk1.7.0_51\\bin\\java.exe -DskipTests=true -DnetbeansProjectMappings= -Dmaven.ext.class.path=\"E:\\Java\\NetBeans 8.0\\java\\maven-nblib\\netbeans-eventspy.jar\" org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
                                                                        
------------------------------------------------------------------------
Building maven-messycode 1.0.0
------------------------------------------------------------------------

--- exec-maven-plugin:1.2.1:exec (default-cli) @ maven-messycode ---
你好
你好
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 0.696s
Finished at: Wed Apr 30 10:12:09 CST 2014
Final Memory: 5M/154M
------------------------------------------------------------------------

############################################################################
use install


cd F:\NBProject\maven-messycode; JAVA_HOME=E:\\Java\\jdk1.7.0_51 cmd /c "\"\"E:\\Java\\NetBeans 8.0\\java\\maven\\bin\\mvn.bat\" -DskipTests=true -Dmaven.ext.class.path=\"E:\\Java\\NetBeans 8.0\\java\\maven-nblib\\netbeans-eventspy.jar\" install\""
Scanning for projects...
                                                                        
------------------------------------------------------------------------
Building maven-messycode 1.0.0
------------------------------------------------------------------------

--- maven-resources-plugin:2.5:resources (default-resources) @ maven-messycode ---
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory F:\NBProject\maven-messycode\src\main\resources

--- maven-compiler-plugin:2.3.2:compile (default-compile) @ maven-messycode ---
Compiling 1 source file to F:\NBProject\maven-messycode\target\classes
com/runshine/maven/messycode/Main.java:[14,16] BASE64Decoder���ڲ�ר�� API, ���ܻ���δ�����а���ɾ��
com/runshine/maven/messycode/Main.java:[14,47] BASE64Decoder���ڲ�ר�� API, ���ܻ���δ�����а���ɾ��

--- maven-resources-plugin:2.5:testResources (default-testResources) @ maven-messycode ---
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory F:\NBProject\maven-messycode\src\test\resources

--- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ maven-messycode ---
No sources to compile

--- maven-surefire-plugin:2.10:test (default-test) @ maven-messycode ---
Tests are skipped.

--- maven-jar-plugin:2.3.2:jar (default-jar) @ maven-messycode ---
Building jar: F:\NBProject\maven-messycode\target\maven-messycode-1.0.0.jar

--- maven-install-plugin:2.3.1:install (default-install) @ maven-messycode ---
Installing F:\NBProject\maven-messycode\target\maven-messycode-1.0.0.jar to F:\MavenRepository\com\runshine\maven-messycode\1.0.0\maven-messycode-1.0.0.jar
Installing F:\NBProject\maven-messycode\pom.xml to F:\MavenRepository\com\runshine\maven-messycode\1.0.0\maven-messycode-1.0.0.pom
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 1.397s
Finished at: Wed Apr 30 10:33:01 CST 2014
Final Memory: 11M/121M
------------------------------------------------------------------------

############################################################################

Then,use install,I can't resolve the problem.
And if need add env-arg to every build-procedure by hand,it's terrible.
Comment 3 Milos Kleint 2014-04-30 04:55:08 UTC
have you tried setting project.build.sourceEncoding property in your pom? That's effectively needed for the project's maven plugins to know your encoding if it differs from the platform default. In 8.0 if you set this property in the pom, we will also set -Dfile.encoding=X to every build of yours. That's what issue 224526 is about.
Comment 4 runshine 2014-04-30 05:18:58 UTC
(In reply to Milos Kleint from comment #3)
> have you tried setting project.build.sourceEncoding property in your pom?
> That's effectively needed for the project's maven plugins to know your
> encoding if it differs from the platform default. In 8.0 if you set this
> property in the pom, we will also set -Dfile.encoding=X to every build of
> yours. That's what issue 224526 is about.

Yes,I was.And still is.
-----pom-----
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.runshine</groupId>
    <artifactId>maven-messycode</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
</project>
Comment 5 V0d01ey 2016-06-15 06:08:59 UTC
The problem is solved for me by adding system variable:
MAVEN_OPTS="-Dfile.encoding=UTF8"
Comment 6 V0d01ey 2016-07-20 05:25:13 UTC
(In reply to V0d01ey from comment #5)
> The problem is solved for me by adding system variable:
> MAVEN_OPTS="-Dfile.encoding=UTF8"

Sorry. The problem didn't solved in this way.