junitreport ant 任务给出 java.lang.OutOfMemoryError: Java 堆空间
我正在从 ant 脚本运行 junit 测试。测试成功运行,因此 ant 继续执行 junitreport 任务来创建 html 报告。此任务失败并出现 java.lang.OutOfMemoryError: Java 堆空间错误
。
如何增加此任务的堆大小?或者有其他方法可以解决这个错误吗?
一些附加信息:
它工作正常,直到我添加了 40 个附加测试,
我查看了测试的 xml 输出,它看起来很合理,即它没有充满长错误消息。
I'm running junit tests from an ant script. The tests run successfully so ant moves on to the the junitreport task to create the html report. This task is failing with a java.lang.OutOfMemoryError: Java heap space error
.
How can I increase the heap size for this task? Or is there another way to resolve this error?
Some additional information:
It was working fine until I added 40 additional tests
I've had a look at the xml output of the tests and it looks reasonable i.e. it's not full of long error messages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 ANT_OPTS 环境变量来增加 ant 使用的堆大小
you can use the ANT_OPTS environment variable to increase the heap size ant uses
此错误已在 ANT bug 34342 中引发。普遍的共识是,这是由于用于生成报告的 XSLT 内存消耗过多造成的,并且不会在 ANT 中修复。
对我有用的是增加传递给 ant 的最大堆大小,例如 -Xmx3304m。正如这里提到的其他一些答案,您可以使用 ANT_OPTS 将最大堆大小传递给 ant。
关于实际最大堆大小值,建议为物理内存的 1/4 或 1GB,以较小者为准。但是,您可能需要超出 1GB 限制才能避免此内存错误。请参阅垃圾收集器人体工程学指南甲骨文网站。
This error has been raised in ANT bug 34342. The general consensus is that it's caused by excessive memory consumption in the XSLT used to generate the report, and it WON'T be fixed in ANT.
What has worked for me has been to increase the maximum heap size passed to ant, eg -Xmx3304m. As some of the other answers here mentioned, you can use ANT_OPTS to pass the maximum heap size to ant.
Regarding the actual maximum heap size value, it is recommended that it should be either 1/4th of physical memory or 1GB, whichever is smaller. You may need to go beyond the 1GB limit to avoid this memory error however. See Garbage Collector Ergonomics guide on the Oracle website.
您可以使用在
junit
任务本身中设置的maxmemory
。正如文档所解释的,
You can use the
maxmemory
set withinjunit
task itself.As the docs explain,
“
maxmemory="###m
” 似乎仅在您使用 fork 时才起作用,如果您不使用 fork(像我一样),则它不会被使用,您必须使用ANT_OPTS
更改堆。The "
maxmemory="###m
" appears to ONLY work if you use fork, If you aren't using fork (like I am) it doesn't get used, You have to use theANT_OPTS
to change the heap.