Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set -Dfile.encoding within ant's build.xml?

I've got java source files with iso-8859-1 encoding. When I run ant, I get "warning: unmappable character for encoding UTF-8". I can avoid this if I run ant -Dfile.encoding=iso-8859-1 or add encoding="ISO-8859-1" to each javac statement.

Is there a way to set the property globally within build.xml? <property name="file.encoding" value="ISO-8859-1"> does not work. I know that I can add a foo=ISO-8859-1 property and set encoding="${foo}" to each javac statement, but I'm trying to avoid that.

like image 322
neu242 Avatar asked Aug 27 '09 07:08

neu242


People also ask

Where is build xml in Ant?

Typically, Ant's build file, called build. xml should reside in the base directory of the project. However, there is no restriction on the file name or its location.


1 Answers

If you've got files encoded in a particular way, it's probably best to tell javac that rather than forcing the whole JVM to use a particular encoding. The javac task has an encoding attribute for this reason.

<javac srcdir="${src.dir}" destdir="${build.classes.dir}" encoding="iso-8859-1" /> 

But really, you should just convert the source files to UTF-8. Everything tastes better in UTF-8. :)

like image 91
Dominic Mitchell Avatar answered Oct 03 '22 21:10

Dominic Mitchell