You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@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.
$ 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 ������
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?
Reacted by Edward Zhang, Alexander Kapitman and owl
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?
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.
Reacted by leo, Wang Jun, code, xffish, FGFW and iwascy
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!
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.
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.
Activity
fbricon commentedon Mar 24, 2018
Works for me:
Since this is a debugger issue, I'll let @yaohaizh, @andxu and co investigate (they should be familiar with Chinese characters).
fbricon commentedon Mar 24, 2018
please open an issue in https://github.com/Microsoft/vscode-java-debug/issues
xpf7622 commentedon Mar 25, 2018
@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?
fbricon commentedon Mar 25, 2018
Yes and yes
andxu commentedon Mar 29, 2018
@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.
yiailake commentedon Apr 4, 2018
$ 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" HelloThe output is
������testforstephen commentedon Apr 11, 2018
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?
gorkem commentedon Apr 12, 2018
@testforstephen What would be the way for the server to receive the file encoding? Is it part of the settings?
testforstephen commentedon Apr 12, 2018
Maven pom.xml file supports encoding config:
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.prefswith contentencoding/<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.encodingto override the Java Compiler Encoding?gorkem commentedon Apr 12, 2018
I think maven and gradle settings are already respected by the server. Are the standalone Java files causing the mischief?
4 remaining items
fbricon commentedon Jun 11, 2018
@testforstephen @andxu can any of you guys look into providing a fix?
testforstephen commentedon Jun 15, 2018
@SummerSun Could you help fix this issue?
testforstephen commentedon Oct 10, 2018
@Fubuchi This looks like a bug of gradle eclipse plugin . See gradle/gradle#898
testforstephen commentedon Oct 10, 2018
@Fubuchi For gradle project, here is a possible workaround.
In the
.settings/folder, manually add a fileorg.eclipse.core.resources.prefswith contents below:close your vscode window. then remove
bin/folder and clean the stale workspace cache.The cache directory for different OS:
after that, reload your project to vscode.
xuzimianxzm commentedon Nov 12, 2018
I solved this problem.
The following configuration is added to the pom.xml file:
https://www.cnblogs.com/xuzimian/p/9947481.html
codemonoling commentedon Dec 20, 2018
@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!
xflcx1991 commentedon Jan 14, 2019
Great! I solve the problem after this action.No maven or gradle project.
q11g commentedon Feb 18, 2019
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.
yaohaizh commentedon Feb 18, 2019
@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.q11g commentedon Feb 21, 2019
Yes, the issue cannot be reproed with the nightly build. Thanks!