Search code examples
javaantcharacter-encodingjavac

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.


Solution

  • A few options:

    1. add -Dfile.encoding=iso-8859-1 to your ANT_OPTS environment variable
    2. use <presetdef> to setup defaults for all of your <javac> invocations