1

I run code by java, Unicode character can be showed correct but when i run code by maven (Mvn clean test) Unicode character show incorrect. I have user extent report and extend report show log with incorrect Unicode character, too

<groupId>groupId</groupId>
<artifactId>api</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                 <encoding>UTF-8</encoding>
                <fork>true</fork>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>.\testsuites\run1.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.9</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.11</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.11</version>
    </dependency>
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>4.0.9</version>
    </dependency>
    <dependency>
        <groupId>com.relevantcodes</groupId>
        <artifactId>extentreports</artifactId>
        <version>2.41.2</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20180130</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>javax.mail-api</artifactId>
        <version>1.6.0</version>
    </dependency>
    <dependency>
        <groupId>com.samczsun</groupId>
        <artifactId>skype4j</artifactId>
        <version>0.1.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.4.6</version>
    </dependency>

    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.pdfbox</groupId>
        <artifactId>pdfbox</artifactId>
        <version>2.0.11</version>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.ashot</groupId>
        <artifactId>ashot</artifactId>
        <version>1.5.4</version>
    </dependency>
    <dependency>
        <groupId>net.gpedro.integrations.slack</groupId>
        <artifactId>slack-webhook</artifactId>
        <version>1.4.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>ooxml-schemas</artifactId>
        <version>1.3</version>
    </dependency>

    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-sheets</artifactId>
        <version>v4-rev525-1.23.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-drive</artifactId>
        <version>v3-rev124-1.23.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.api-client</groupId>
        <artifactId>google-api-client</artifactId>
        <version>1.23.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.oauth-client</groupId>
        <artifactId>google-oauth-client-jetty</artifactId>
        <version>1.23.0</version>
    </dependency>
    <dependency>
        <groupId>com.jayway.jsonpath</groupId>
        <artifactId>json-path</artifactId>
        <version>2.4.0</version>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>3.3.0</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency>

    <dependency>
        <groupId>net.javacrumbs.json-unit</groupId>
        <artifactId>json-unit</artifactId>
        <version>1.5.0</version>
        <scope>compile</scope>
    </dependency>

</dependencies>

@Test(enabled = true)
public void Demo_001() throws IOException {

    String text = "Đây là văn bản tiếng việt";
    System.out.println(text);

            //extent report log
    BaseObject.addReportLog(LogType.INFO, text);

}

Actual result : ?y l v?n b?n ti?ng vi?t

Expected result : Đây là văn bản tiếng việt

5
  • MCVE, please. Commented Sep 12, 2019 at 4:52
  • 1
    There are many possible causes, maven being not the most probable one: is your Java source code really encoded in UTF-8? On which operating system are you running your code? What codepage/encoding/font does the displaying console use? Commented Sep 12, 2019 at 6:27
  • I resolved my issus by add argLine : <argLine>-Dfile.encoding=UTF-8</argLine> To POM.xml on plugin maven-surefire-plugin Commented Sep 12, 2019 at 7:49
  • @Raw2008 you can write it as answer and accept it Commented Sep 12, 2019 at 8:21
  • @barbsan tks your guide Commented Sep 12, 2019 at 14:06

2 Answers 2

1

I resolved my issue by add DFile encoding UTF-8 on sureFire Plugin at POM.xml

      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <argLine>-Dfile.encoding=UTF-8</argLine>
                <suiteXmlFiles>
                    <suiteXmlFile>.\testsuites\run1.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
Sign up to request clarification or add additional context in comments.

Comments

0

Since version 3.0.0-M1, both surefire and failsafe plugins have the encoding parameter. You can configure it like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.1.2</version>
    <configuration>
        <encoding>UTF-8</encoding>
    </configuration>
</plugin>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.