如何在 ant 中为 junit 测试设置 file.encoding? [英] How do I set file.encoding for a junit test in ant?
问题描述
我对 文件还没有完成.编码和蚂蚁.如何在 ant 中为 junit 测试设置 file.encoding?junit ant 任务不像 javac 任务那样支持 encoding 属性.
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.
我试过运行 «ant -Dfile.encoding=UTF-8» 和 «ANT_OPTS="-Dfile.encoding=UTF-8" ant» 没有成功.测试中的 System.getProperty("file.encoding") 仍然返回 MacRoman.
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 支持子元素 <jvmarg ...>
应该做你想做的事.
JUnit supports a child element <jvmarg ...>
which should do what you want.
<junit fork="yes">
<jvmarg value="-Dfile.encoding=UTF-8"/>
...
</junit>
我假设您使用了 fork=yes
属性,因为这会为测试运行启动一个新的 JVM,因此您在命令行中将参数发送到 ant ant -Dfoo=bar
不一定会传播到运行测试的 JVM.
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.
这篇关于如何在 ant 中为 junit 测试设置 file.encoding?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!