子 java 任务中出现不一致的 NoClassDefFoundError
我的 ant 构建脚本以使用 fork=true 的 java 任务开始
<java fork="true"
classname="org.apache.tools.ant.launch.Launcher"
jvm="${java.home}/bin/java"
classpathref="class.path">
<arg value="-f" />
<arg value="${ant.file}" />
<arg value="generate" />
</java>
指向同一 ant 构建文件中的另一个任务。 此任务通过指向另一个文件的子任务启动另一个目标。
<subant verbose="true" target="replace">
<fileset dir="${basedir}" includes="refactor.xml" />
</subant>
此文件 refactor.xml 使用 fork=true 再次启动 java 任务。
<java classpathref="class.path"
classname="namespace.Tool"
fork="true"/>
奇怪的行为是:一切正常,除了偶尔我会收到 namespace.Tool
java 源文件的 NoClassDefFoundError
错误。 例如,关闭、重新打开文件后,错误可能会消失,但没有可重现的行为。
我尝试避免 subant 结构(用于整理),但这没有帮助。
最后引用的 class.path 是这样的:
<path id="class.path">
<pathelement location="../common/bin" />
<pathelement location="./bin" />
<fileset dir="${build.dir}">
<include name="...jar" />
</fileset>
</path>
Any ideas?
My ant build script starts with a java task that uses fork=true
<java fork="true"
classname="org.apache.tools.ant.launch.Launcher"
jvm="${java.home}/bin/java"
classpathref="class.path">
<arg value="-f" />
<arg value="${ant.file}" />
<arg value="generate" />
</java>
The <arg value="generate" />
points to another task in the same ant build file.
This task starts another target with a subant task that points to another file.
<subant verbose="true" target="replace">
<fileset dir="${basedir}" includes="refactor.xml" />
</subant>
This file refactor.xml starts a java task again with fork=true.
<java classpathref="class.path"
classname="namespace.Tool"
fork="true"/>
The strange behaviour is: everything works fine, except once in a while I get the NoClassDefFoundError
error for the namespace.Tool
java source file.
After e.g. closing, reopening the file the error may disappear, however there is no reproducible behaviour.
I tried avoiding the subant construction (used to unclutter) but this doesn't help.
Finally the class.path that is referenced is like this:
<path id="class.path">
<pathelement location="../common/bin" />
<pathelement location="./bin" />
<fileset dir="${build.dir}">
<include name="...jar" />
</fileset>
</path>
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原因是
。一旦 Ant 任务序列中的其他步骤(例如删除了文件夹)中,Eclipse 就会重新编译此
bin
文件夹。 Eclipse 中的默认设置是在此时重新编译所有代码。因此,Ant 进程可能会或可能不会在此
bin
文件夹中找到特定类,从而导致不一致的NoClassDefFoundError
。Cause was
<pathelement location="./bin" />
.This
bin
folder was recompiled by Eclipse as soon as in other steps in the sequence of Ant tasks e.g. a folder was deleted. The default setting in Eclipse is to recompile all code at such a moment.As a result the Ant process may or may not find a specific class in this
bin
folder resulting in the inconsistentNoClassDefFoundError
.