I'm writing an ANT task in Java.
In my build.xml I specify parameters, which should be read from my java class. Problems occur, when I use special characters, like german umlauts (Ö,Ä,Ü) in these parameters. In my java task they appear as ?-characters (using System.out.print from within eclipse).
All my files are encoded as UTF-8. and my build.xml has the corresponding declaration:
<?xml version="1.0" encoding="UTF-8" ?>
For the details of writing the task: I do it according to http://ant.apache.org/manual/develop.html (especially Point 5 nested elements). I have nested elements in my task like:
<parameter name="test" value="ÖÄÜtest"/>
and a java method:
public void addConfiguredParameter(Parameter prop) {
System.out.println(prop.getValue());
//prints ???test
}
to read the parameter values.
There are several transcoding operations going on here:
System.out
PrintStream from UTF-16 strings to the platform encodingPrintStream
Encoded as UTF-8, you would expect the following encoded values in your XML file:
The problem somehow vanished into thin air and was probably already fixed by switching everything to utf-8, but maybe eclipse didn't react so fast. Anyway I couldn't reproduce the error.
A problem which remained was, that when I referred to a build.properties file (which uses the characters mentioned) from my build.xml - then my java task still didn't get the characters right. But I could circumvent this by using \u and the hex representation of the letters - although that's not really convenient!
Have you tried starting java with the following parameter?