ant - 尝试复制到 /lib/endorsed,库在 Windows 7 中无法用于下一个任务
在 Windows 7 上,我有一个 ant 目标,它将 xalan 库复制到 jdk 认可的目录中,以便可以执行下一个 xslt 转换任务。
ant 目标第一次运行时,xslt 转换失败。第二次运行时,jar 文件已经位于正确的位置,并且 xslt 转换成功。
ant 目标第一次运行时,看起来文件复制成功。这感觉像是一个时间问题,但我不知道我能做些什么来解决它。
这是我的复制任务:
<mkdir dir="${java.home}\lib\endorsed"/>
<copy file="${basedir}\xalan.jar" tofile="${java.home}\lib\endorsed\xalan.jar"/>
以前有人见过这样的东西吗?
On Windows 7 I have an ant target that copies a xalan library into the jdk endorsed directory so that the next xslt transformation task can occur.
The first time that the ant target runs, the xslt transformation fails. The second time it runs the jar file is already in the correct place and the xslt tranformation succeeds.
The first time that the ant target runs, it looks like the file copied successfully. It feels like a timing issue, but I don't know what I can do to get around it.
Here is my copy task:
<mkdir dir="${java.home}\lib\endorsed"/>
<copy file="${basedir}\xalan.jar" tofile="${java.home}\lib\endorsed\xalan.jar"/>
Has anyone seen anything like this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题在于,当执行 XSLT 任务时,JVM(运行 Ant 本身)已经从认可的目录加载了类。将 xalan jar 复制到认可的目录后,您必须派生另一个 JVM 实例。
你用什么来运行xslt?如果是 XSLT 任务,您不能只使用工厂元素来加载 xalan 吗?如果是java任务,则使用fork属性在另一个JVM实例中启动xslt处理。
I think the problem is that when the XSLT task is executes, the JVM (which runs Ant itself) has already loaded classes from the endorsed directory. You would have to fork another JVM instance after having copied the xalan jar into the endorsed dir.
What are you using to run xslt? If it's the XSLT task, couldn't you just use the factory element in order to load xalan ? If it's a java task, then use the fork attribute to start the xslt processing in another JVM instance.
通常,Java 安装在 Windows 7 上的
Program Files
目录中,因此您的 JAVA_HOME 将指向Program Files
目录中的某个位置,并且普通用户没有权限在其中创建新文件那里。另外,将库添加到认可路径可能会对其他程序产生副作用,因此您应该更好地使用 XSLT-Task 的
classpath
属性:Usually Java is installed into the
Program Files
directory on Windows 7, therefore your JAVA_HOME will point somewhere insideProgram Files
directory and regular users do not have the permission to create new files in there.Additionally adding a library to the endorsed path can have side-effects for other programs therefore you should better use the
classpath
attribute of the XSLT-Task: