How to install -Dfile.encoding in ant build.xml?

I have java source files encoded with iso-8859-1. When I run ant, I get a warning: unmappable character for UTF-8 encoding. "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 inside build.xml? <property name = "file.encoding" value = "ISO-8859-1"> does not work. I know that I can add the property foo = ISO-8859-1 and set the encoding = "$ {foo}" to every javac statement, but I try to avoid this.

+43
java character-encoding javac ant
Aug 27 '09 at 7:09
source share
4 answers

Several variants:

  • add -Dfile.encoding=iso-8859-1 to the ANT_OPTS environment ANT_OPTS
  • use <presetdef> to set defaults for all your <javac> calls
+30
Aug 27 '09 at 7:37
source share

If you have files encoded in a certain way, it is best to say javac rather than force the JVM to use a specific encoding. For this reason, javac task has an encoding attribute.

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

But in fact, you just need to convert the source files to UTF-8. Everything is better in UTF-8. :)

+60
Aug 27 '09 at 7:42
source share

Before modifying the build file, I get a java compilation error, as shown below.

ApplicationConstant.java:73: error: not applicable character for encoding ascii public static final String INVALID_MDTVERSION_SECOND = " This not compatible with the serverÒ€ℒs Version";

I ran into this error when I used ant java target as:

  <javac encoding="ascii"...> 

Than I have changed below

 <javac encoding="iso-8859-1" ...> 

This issue has been resolved.

+2
Oct. 14 '15 at 15:13
source share

Ant itself cannot set system properties, but if you really want to, you can write a java program that sets the system property and executes it from Ant.

+1
Aug 27 '09 at 7:26
source share



All Articles