Sunday, May 11, 2008

How to learn a new groovy friend Italian accents (and not only)

While updating my webpage-pieces-merger to be groovy, I noticed some odd problem on Italian accents (same would be for German umlaute and so on).


So what is going on with UTF-8?? Why is the encoding wrong, when my java encoding is always right?

When I have a look at the System.properties, I notice that the encoding is:
file.encoding=MacRoman

Alright, so I just have to change that one?
try 1) groovy -c UTF-8 myScript -> NOT WORKING

try 2) first set the encoding in the java options on the console:
export JAVA_OPTS=-Dfile.encoding=UTF-8
after that I get a nice file.encoding=UTF-8

and the text is ok:

so what about setting the property inside the script?

try 3) inside the myScript set System.setProperty("file.encoding","UTF-8")
Nice, I get file.encoding=UTF-8 but for some reason the accents are messed up again.


I really wonder why try 3 is not working, probably setting this inside the process is too late? Wrong JVM? Hmmm... really no idea about it. Try 2 is working ok, but I don't like the fact that I have to set a system variable before. I hope to find a solution soon.

2 comments:

Matthias Bohlen said...

set the system property
groovy.source.encoding=UTF-8

You can do that on the command line:
export JAVA_OPTS=-Dgroovy.source.encoding=UTF-8

Or in Eclipse.ini (if you work with Eclipse)
-Dgroovy.source.encoding=UTF-8

Cheers
Matthias

moovida said...

Now that is cool :-)
Thanks for stopping by and enlighting me Matthias!