Ant由于 Xalan (XSLT) 安全处理功能而失败
我的 junit 测试在 Eclipse 环境中通过 ant 1.7 运行,但执行 junitreport 任务时构建失败:
构建失败 .../build.xml:222:应用转换时出错: javax.xml.transform.TransformerException:java.lang.RuntimeException: 使用扩展函数 'xalan://org.apache.tools.ant.util.StringUtils:replace' 当安全处理功能设置为 true 时不允许。
我试图弄清楚如何使 junitreport 任务禁用安全处理功能(我不需要并且目前仅以我的方式),但我不知道如何,因为该任务没有要禁用的属性它。或者我应该做其他事情来使这项工作成功?
My junit tests run via ant 1.7 from within my Eclipse environment but the build failes when the junitreport task is performed:
BUILD FAILED
.../build.xml:222: Errors while applying transformations:
javax.xml.transform.TransformerException: java.lang.RuntimeException:
Use of the extension function 'xalan://org.apache.tools.ant.util.StringUtils:replace'
is not allowed when the secure processing feature is set to true.
I tried to figure out how to make the junitreport task disable the secure processing feature (which I don't need and is only in my way at this point) but I have no clue how since the task doesn't have an attribute to disable it. Or should I do something else to make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能与 Ant 1.8.2 中的已知错误有关。
Ant 1.8.3 的错误修复已提交,但 Apache Ant 1.8截至 2012 年 1 月 25 日,.3 尚未发布。此 bug 修复的 WHATSNEW 描述是:
一旦 Ant 1.8.3 发布并合并到 Eclipse 中Ant插件,这个问题应该可以解决。
同时,您可以编辑构建脚本,以便它仅在从命令行(而不是从 Eclipse 中)运行 Ant 时运行 JUnitReport 目标。要做出此确定,请在常规 %ANT_HOME%/lib 文件夹中查找 Eclipse Ant 插件文件夹中不存在的文件(或在其中创建一个文件),然后设置一个属性(如果检测到文件。 EG
就在 JUnit 目标结束之前:
在 JUnitReport 目标开始处:
上述 Ant 片段可以正常工作,因为只有当 Ant 从 Eclipse 中运行时,ant.home 才会设置为 Eclipse Ant Plugin 文件夹。当 Ant 从命令行运行时,ant.home 将匹配您的 ANT_HOME 环境变量。还应该有一个 eclipse.running Ant 属性,但我无法检测到此属性。
另一个临时选项是从 Apach Ant 上的此链接下载 Ant nightly 版本的最新 JAR 文件项目页面,然后将这些 JAR 文件放入相应的 Eclipse Ant 插件子文件夹中。不保证这会起作用。
This may be related to a very similar known bug in Ant 1.8.2.
The bugfix for Ant 1.8.3 has been committed, but Apache Ant 1.8.3 has yet to be released as of Jan 25 2012. The WHATSNEW description for this bugfix is:
Once Ant 1.8.3 is released and is incorporated into the Eclipse Ant plugin, this issue should be resolved.
In the meantime, you can edit your build script so it only runs the JUnitReport target if running Ant from a command line, rather than from within Eclipse. To make this determination, look for a file present in your regular %ANT_HOME%/lib folder that is not present in your Eclipse Ant plugin folder (or create a file there), then set a property if the file is detected. E.G.
Just before the end of your JUnit target:
At the beginning of your JUnitReport target:
The above Ant fragments work because ant.home is set to the Eclipse Ant Plugin folder only when Ant is run from within Eclipse. When Ant is run from a command line, ant.home will match your ANT_HOME environment variable. There is also supposed to be an eclipse.running Ant property, but I could not detect this property.
Another interim option is to download the newest JAR files of Ant nightly builds from this link on the Apach Ant project page, then placing those JAR files within the corresponding Eclipse Ant plugin sub-folder. No guarantees this will work.
您始终可以直接注释掉该任务。
You can always just comment the task out.