简体   繁体   中英

How do I set file.encoding for a junit test in ant?

I'm not quite done with file.encoding and ant . How do I set the file.encoding for junit tests in ant? The junit ant task doesn't support the encoding attribute like the javac task does.

I've tried running «ant -Dfile.encoding=UTF-8» and «ANT_OPTS="-Dfile.encoding=UTF-8" ant» without success. System.getProperty("file.encoding") within a test still returns MacRoman .

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

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

I assume you were using the fork=yes attribute since this starts a new JVM for the test run, thus the parameters you send into ant at the command line ant -Dfoo=bar do not necessarily propagate to the JVM running the tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM