Skip to content

chinese character don't display appropriate. #479

Closed

Description

@xpf7622

Java code:
// Hello world
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World! 汉字!");
}
}

output as follow:

Hello World! 姹夊瓧锛�

but java file have the default code utf-8. and Debugger for java default also utf8, why the output is abnormal character!

Activity

  1. fbricon commented on Mar 24, 2018

    @fbricon
    Collaborator

    Works for me:

    screen shot 2018-03-24 at 2 49 23 pm

    Since this is a debugger issue, I'll let @yaohaizh, @andxu and co investigate (they should be familiar with Chinese characters).

  2. fbricon commented on Mar 24, 2018

    @fbricon
    Collaborator
  3. xpf7622 commented on Mar 25, 2018

    @xpf7622
    Author

    @fbricon your java file is utf-8? my java file is default utf-8. your files encoding?
    Are you sure your ext is Debugger for Java?

  4. fbricon commented on Mar 25, 2018

    @fbricon
    Collaborator

    Yes and yes

  5. andxu commented on Mar 29, 2018

    @andxu
    Collaborator

    @xpf7622 Seems it is related to the default encoding settings of eclipse, open the project with eclipse and change the encoding for the project and the generated class will have the right encoding.

  6. yiailake commented on Apr 4, 2018

    @yiailake

    $ cd /Users/kevinfeng/Desktop/java ; /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/jre/bin/java -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:63788 -Dfile.encoding=UTF-8 -cp "/Users/kevinfeng/Library/Application Support/Code/User/workspaceStorage/b72b50a9aa05f002d6a626eedc811d53/redhat.java/jdt_ws/jdt.ls-java-project/bin" Hello
    The output is ������

  7. testforstephen commented on Apr 11, 2018

    @testforstephen
    Collaborator

    jdt compiler will use the os default encoding to compile the source code, no regarding what encode is used in vscode editor. If the user's system is Chinese, the system default encoding could be GBK and use that to compile the UTF-8 source file will cause messy string in .class.

    Eclipse IDE provides UI for setting text file encoding, and the compiler will consume that automatically to keep the consistent. But in VSCode, the underlying compiler will not consume the encoding that the user saw in his editor.

    Is it possible to let the jdt compiler to read the source file with the vscode editor encoding? Or at least provide a way to let the user to configure the compiler encoding?

    @fbricon Given your guys are more familiar with the eclipse base code, any thoughts on this?

  8. gorkem commented on Apr 12, 2018

    @gorkem
    Contributor

    @testforstephen What would be the way for the server to receive the file encoding? Is it part of the settings?

  9. testforstephen commented on Apr 12, 2018

    @testforstephen
    Collaborator

    Maven pom.xml file supports encoding config:

    <project>
      ...
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
      ...
    </project>
    

    Gradle supports setting Java Compiler Encoding:
    compileJava.options.encoding = 'UTF-8'

    When importing maven or gradle project into VSCode, java language server will translate the encoding info into a file .settings/org.eclipse.core.resources.prefs with content encoding/<project>=XXX. That's no problem.

    But when opening simple java files (non eclipse project files) in VSCode, there is no way to override the compiler encoding. How about adding a new User Settings like java.file.encoding to override the Java Compiler Encoding?

  10. gorkem commented on Apr 12, 2018

    @gorkem
    Contributor

    I think maven and gradle settings are already respected by the server. Are the standalone Java files causing the mischief?

  11. 4 remaining items

  12. fbricon commented on Jun 11, 2018

    @fbricon
    Collaborator

    @testforstephen @andxu can any of you guys look into providing a fix?

  13. testforstephen commented on Jun 15, 2018

    @testforstephen
    Collaborator

    @SummerSun Could you help fix this issue?

  14. self-assigned this
    on Jul 23, 2018
  15. testforstephen commented on Oct 10, 2018

    @testforstephen
    Collaborator

    @Fubuchi This looks like a bug of gradle eclipse plugin . See gradle/gradle#898

  16. testforstephen commented on Oct 10, 2018

    @testforstephen
    Collaborator

    @Fubuchi For gradle project, here is a possible workaround.

    In the .settings/ folder, manually add a file org.eclipse.core.resources.prefs with contents below:

    eclipse.preferences.version=1
    encoding//src/main/java=UTF-8
    encoding//src/main/resources=UTF-8
    encoding//src/test/java=UTF-8
    encoding/<project>=UTF-8
    

    close your vscode window. then remove bin/ folder and clean the stale workspace cache.
    The cache directory for different OS:

    Windows : %APPDATA%\Code\User\workspaceStorage\
    MacOS : $HOME/Library/Application Support/Code/User/workspaceStorage/
    Linux : $HOME/.config/Code/User/workspaceStorage/
    

    after that, reload your project to vscode.

  17. xuzimianxzm commented on Nov 12, 2018

    @xuzimianxzm

    I solved this problem.
    The following configuration is added to the pom.xml file:

    <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    

    https://www.cnblogs.com/xuzimian/p/9947481.html

  18. codemonoling commented on Dec 20, 2018

    @codemonoling

    @testforstephen
    #479 (comment)

    In the .settings/ folder, manually add a file org.eclipse.core.resources.prefs with contents below:
    eclipse.preferences.version=1
    encoding//src/main/java=UTF-8
    encoding//src/main/resources=UTF-8
    encoding//src/test/java=UTF-8
    encoding/=UTF-8

    and remove ./bin folder ,I solve the chinese character problem,thank you!

  19. xflcx1991 commented on Jan 14, 2019

    @xflcx1991

    @Fubuchi For gradle project, here is a possible workaround.

    In the .settings/ folder, manually add a file org.eclipse.core.resources.prefs with contents below:

    eclipse.preferences.version=1
    encoding//src/main/java=UTF-8
    encoding//src/main/resources=UTF-8
    encoding//src/test/java=UTF-8
    encoding/<project>=UTF-8
    

    close your vscode window. then remove bin/ folder and clean the stale workspace cache.
    The cache directory for different OS:

    Windows : %APPDATA%\Code\User\workspaceStorage\
    MacOS : $HOME/Library/Application Support/Code/User/workspaceStorage/
    Linux : $HOME/.config/Code/User/workspaceStorage/
    

    after that, reload your project to vscode.

    Great! I solve the problem after this action.No maven or gradle project.

  20. q11g commented on Feb 18, 2019

    @q11g

    I hit the same issue yesterday. It is great that we have a workaround, but unfortunately the developer experience is less than ideal, when compared with IntelliJ... When can we have a proper fix? Thanks.

  21. yaohaizh commented on Feb 18, 2019

    @yaohaizh
    Collaborator

    @zhangqi5 The issue is fixed by b5e6330

    You can find the latest nightly build for testing: http://download.jboss.org/jbosstools/jdt.ls/staging/java-0.39.0-1379.vsix

    Make sure you invoke Java: Clean workspace ... to delete stale object/cache.

  22. q11g commented on Feb 21, 2019

    @q11g

    Yes, the issue cannot be reproed with the nightly build. Thanks!

  23. added this to the Mid February 2019 milestone on Feb 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions