How to set file.encoding for junit test in ant?

I didn’t quite do with file.encoding and ant . How to set file.encoding for junit tests in ant? The junit ant task does not support the encoding attribute, as the javac task does.

I tried using "ant -Dfile.encoding = UTF-8" and "ANT_OPTS =" - Dfile.encoding = UTF-8 "ant" without success. System.getProperty ("file.encoding") in the test still returns MacRoman.

+4
source share
1 answer

JUnit supports a <jvmarg ...> child element, which should do what you want.

 <junit fork="yes"> <jvmarg value="-Dfile.encoding=UTF-8"/> ... </junit> 

I assume that you used the fork=yes attribute since it launches a new JVM for a test run, so the parameters you send to ant at the ant -Dfoo=bar command line do not necessarily apply to the JVM that runs the tests.

+16
source

All Articles