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

試著忘記壹切 提交于 2019-12-07 10:07:09

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/1686271/how-do-i-set-file-encoding-for-a-junit-test-in-ant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!