Tired of seeing garbled Eclipse Console output? Here is a quick and dirty tutorial for getting Unicode output in Eclipse Console.
Fact: You will not get Unicode output in Eclipse Console while using System.out directly in Windows. See Eclipse BUG #13865.
1. add -Dfile.encoding=UTF-8 to your eclipse.ini
2. make sure your Eclipse Console font supports Unicode. You can try it out by typing unicode characters directly to console with keyboard. Console Font is set in Window -> Preferences -> General -> Appearance -> Colors and Fonts -> Debug -> Console Font
3. if you are NOT using Windows, set your system encoding to UTF-8. You should now see Unicode characters in Console after restarting Eclipse.
4. if you are using Windows or do not want to change your OS encoding, you will have to avoid using System.out stream directly. Instead, wrap it up with java.io.PrintStream:
PrintStream sysout = new PrintStream(System.out, true, "UTF-8");
sysout.println("\u2297\u0035\u039e\u322F\u5193");
5. if you are using Log4J with ConsoleAppender, make sure to set the encoding property to UTF-8. Example:
#TRACE appender
log4j.appender.stdout.trace=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.trace.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.trace.encoding=UTF-8
log4j.appender.stdout.trace.layout.ConversionPattern=%p [%c] - %m%n
log4j.appender.stdout.trace.Threshold=TRACE
Happy development!
Error'd: Hypersensitive
1 day ago
This was helpful in solving a problem I was having, thanks. But changing eclipse.ini didn't work for me.
ReplyDeleteInstead, I altered the JRE configuration :
Window > Preferences > Java > Installed JREs ; select JRE ; select Edit
add to Default VM Arguments: -Dfile.encoding=UTF-8
you are wrong it is possible to have UTF-8 for windows with System.out simple:
ReplyDeleterefer: http://bytecounts.com/blog/?p=28
rules are actual for Windows too.
akhlystov, setting unicode font does not solve system encoding problems (read more about it: https://bugs.eclipse.org/bugs/show_bug.cgi?id=13865)
ReplyDeleteThis may not be an issue with Windows Vista, though I haven't tried it there yet, only on XP. Anyway, it's better to use loggers instead of printing to System.out.
No I'm not talking about fonts. I'm talking about
ReplyDelete1. Open Run Dialog > "your application" > Common Tab > Console Encoding > Other "set it to UTF-8"
2. Open Run Dialog > "your application" > Arguments Tab > VM Arguments > Add "-Dfile.encoding=UTF-8"
and of course Window Menu > General > Workspace > Text file encoding should be set to "UTF-8"
then you can run your application ( doesn't matter Standalone or inside Tomcat)
e.g. this code will work:
public class Hello {
public static void main(String [] args)
{
System.out.println("english letters. русские буквы");
System.out.println("new Date()= " + new Date());
}
Thank you!
ReplyDeleteI didn't need to alter the Console Font, only added -Dfile.encoding=UTF-8 to eclipse.ini
Thank you all for the comments. Adding -Dfile.encoding=UTF-8 to eclipse.ini wroked for me as well.
ReplyDeleteThank you. Helped us alot.
ReplyDeletethanks, worked on OS X, added -Dfile.encoding=UTF-8 to /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.ini
ReplyDeleteThank you, this was unbelievably helpful!
ReplyDeleteThanks a lot, this problem confused me for long days, altering eclipse.ini solved everything.
ReplyDeleteThis one's better, guys :
ReplyDeletehttp://i18ncookbook.com/eclipse_settings
Thanks; worked great - glad to finally be able to see what I'm doing in the console.
ReplyDeleteThanks!
ReplyDeleteBut instead of changing .ini file i did that in eclipse: Window -> Preferences-> General -> Workspace -> Text File Encoding -> Other UTF-8
That was sufficient for me.
Now i get nice error messages in russian :)
I'm an Eclipse newbie, so take this with a grain of salt, but I managed to get around the problem in Eclipse Indigo SR1 simply by going to Edit > Set Encoding, then choosing UTF-8.
ReplyDeleteThanks again! You've helped out me second time:)
ReplyDeleteThis code is great:
ReplyDeletePrintStream sysout = new PrintStream(System.out, true, "UTF-8");
sysout.println("\u2297\u0035\u039e\u322F\u5193");
Thanks!
DJ Guo