从 Ant 脚本中运行 Gant 任务时出现 NoClassDefFoundError
我有一个 Android 构建脚本。它尝试使用 Gant 任务而不是 Ant 目标来完成项目上的自定义工作。有趣的构建脚本部分如下所示:
<taskdef name="gant" classname="org.codehaus.gant.ant.Gant">
<classpath>
<pathelement location="${gant.dir}/gant-1.9.7_groovy-1.8.4.jar" />
</classpath>
</taskdef>
<target name="-pre-build">
<gant target="targetA"/>
<gant target="targetB"/>
<gant target="targetC"/>
<gant target="targetD"/>
<gant target="targetE"/>
</target>
<target name="-pre-compile">
<gant target="targetF"/>
</target>
我的 build.gant 文件肯定有这些目标,但是当使用 Ant 运行构建脚本时,我得到:
(...)\build.xml:55: java.lang.NoClassDefFoundError: groovy/util/AntBuilder
一旦 Ant 命中行:
<gant target="targetA"/>
我使用 Groovy 1.8.4 与Gant 通过 Windows 安装程序文件安装,并通过 Ant 视图安装 Eclipse Helios。 Gant.dir 属性具有有效路径,因此情况并非如此。看起来 Groovy 无法在 build.gant 文件中找到目标,即使它们存在。我什至尝试使用 Gant 任务并提供 build.gant 文件的完整路径,但没有成功。从控制台运行 Ant 脚本时也会发生同样的情况。 Build.gant 文件在 Ant 脚本中可见。
有什么办法可以解决这个问题吗?
I have an Android build script. It tries to use Gant tasks instead of Ant targets for custom work done on project. The interesting build script's part looks the following way:
<taskdef name="gant" classname="org.codehaus.gant.ant.Gant">
<classpath>
<pathelement location="${gant.dir}/gant-1.9.7_groovy-1.8.4.jar" />
</classpath>
</taskdef>
<target name="-pre-build">
<gant target="targetA"/>
<gant target="targetB"/>
<gant target="targetC"/>
<gant target="targetD"/>
<gant target="targetE"/>
</target>
<target name="-pre-compile">
<gant target="targetF"/>
</target>
My build.gant file definitely has those targets, but when running build script with Ant I get:
(...)\build.xml:55: java.lang.NoClassDefFoundError: groovy/util/AntBuilder
as soon as Ant hits line:
<gant target="targetA"/>
I use Groovy 1.8.4 with Gant installed from Windows installer file and Eclipse Helios with Ant view. Gant.dir property has a valid path, so it's not the case. It looks like Groovy can't find targets inside build.gant file even if they are present. I tried even to use Gant task with full path to build.gant file provided, but with no success. The same thing happens when running Ant script from console. Build.gant file is visible in Ant script.
Is there any way to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,这不是 build.gant 中不可见目标的问题,而是 taskdef 类路径中缺少库的问题。以下解决了我的问题:
其中 gant.libs.dir 引用包含 Gant 1.9.7 二进制独立安装 zip 文件中的 gant_groovy1.8-1.9.7.jar 和 groovy-all-1.8.4.jar 的目录。
So, it was not a problem with invisible targets inside build.gant, but rather with missing libraries in taskdef's classpath. The following fixes my problem:
where gant.libs.dir refers to a directory containing gant_groovy1.8-1.9.7.jar and groovy-all-1.8.4.jar from Gant 1.9.7 binary standalone installation zip file.