下载后加载ant库
我正在尝试编写一个 Ant 脚本,该脚本从我们的存储库下载库(ivy 和 svnant),并将它们用作同一构建脚本中的 taskdef。如果所有库都存在或全部缺失,它就可以工作,但如果需要辅助库(如 svnClientAdapter),那么我会收到错误:
jar:file:/home/reillym/.ant/lib/svnant.jar!/org/tigris/subversion/svnant/svnantlib.xml:5: taskdef A class needed by class org.tigris.subversion.svnant.SvnTask cannot be found: org/tigris/subversion/svnclientadapter/SVNClientException
换句话说,如果主库存在或不存在,一切都会很好;但是如果主库存在并且依赖库之一不存在,那么我就会失败。如果没有其他任何更改,第二次调用将会成功。
我尝试从任务和具有相同结果的类中调用检测/下载任务。我的代码是:
<target name="svn-info" depends="load.subverion">
<svn><wcVersion path="${basedir}"/></svn>
</target>
<target name="load.subversion" depends="download.antlib-svn">
<taskdef resource="org/tigris/subversion/svnant/svnantlib.xml">
<!-- needed in case one of libraries was missing from ant's classpath -->
<classpath>
<pathelement location="${user.home}/.ant/lib/svnClientAdapter.jar"/>
<pathelement location="${user.home}/.ant/lib/svnant.jar"/>
<pathelement location="${user.home}/.ant/lib/svnjavahl.jar"/>
</classpath>
</taskdef>
<target name="download.antlib-svn" depends="retrieve.antlib-svn">
<!-- ant target="retrieve.antlib-svn" inheritAll="false"/ -->
</target>
<target name="retrieve.antlib-svn">
<get dest="${user.home}/.ant/lib/svnClientAdapter.jar" usetimestamp="1"
src="${url.ivyrepos}/antlib-svn/svnClientAdapter.jar"/>
<get dest="${user.home}/.ant/lib/svnant.jar" usetimestamp="1"
src="${url.ivyrepos}/antlib-svn/svnant.jar"/>
<get dest="${user.home}/.ant/lib/svnjavahl.jar" usetimestamp="1"
src="${url.ivyrepos}/antlib-svn/svnjavahl.jar"/>
</target>
如果只缺少 svnant.jar,一切都会按预期工作。如果缺少 svnClientAdapter.jar,则任务定义任务上会出现“未找到类”错误;尝试使用该任务时会出现“NoClassDefFoundError”错误。如前所述,我尝试过将retrieve.antlib-svn 目标作为依赖项、“ant”任务和“java”任务(带fork)调用。
这是 Ubuntu 10.10 和 RedHat ELS6 上带有 JDK 1.6.0_11 的 Ant 1.7.0。为简洁起见,删除了检测/避免代码。打开调试后,工作调用和失败调用之间的唯一区别是缺少的 jar 包含在 ant 的类路径中,我尝试在 taskdef 任务中覆盖它。
我不介意生成一个新的顶级 ant 调用,但 ivy.project.invoked-targets 似乎在 1.7.0 中不可用,而且我还没有找到使用相同起始目标调用 ant 的另一种方法。
I'm trying to write an Ant script that downloads libraries (ivy and svnant) from our repository and use them as taskdef's from the same build script. It works if all the libraries are present or all are missing, but if a secondary library is needed (like svnClientAdapter), then I get the error:
jar:file:/home/reillym/.ant/lib/svnant.jar!/org/tigris/subversion/svnant/svnantlib.xml:5: taskdef A class needed by class org.tigris.subversion.svnant.SvnTask cannot be found: org/tigris/subversion/svnclientadapter/SVNClientException
In order words, everything is fine if the primary library does or does not exist; but if the primary libraries exists and one of the dependency libraries does not exist, then I get a failure. If nothing else is changed, a second call will succeed.
I've tried calling the detection/download tasks from an task and from a class with the same result. The code I have is:
<target name="svn-info" depends="load.subverion">
<svn><wcVersion path="${basedir}"/></svn>
</target>
<target name="load.subversion" depends="download.antlib-svn">
<taskdef resource="org/tigris/subversion/svnant/svnantlib.xml">
<!-- needed in case one of libraries was missing from ant's classpath -->
<classpath>
<pathelement location="${user.home}/.ant/lib/svnClientAdapter.jar"/>
<pathelement location="${user.home}/.ant/lib/svnant.jar"/>
<pathelement location="${user.home}/.ant/lib/svnjavahl.jar"/>
</classpath>
</taskdef>
<target name="download.antlib-svn" depends="retrieve.antlib-svn">
<!-- ant target="retrieve.antlib-svn" inheritAll="false"/ -->
</target>
<target name="retrieve.antlib-svn">
<get dest="${user.home}/.ant/lib/svnClientAdapter.jar" usetimestamp="1"
src="${url.ivyrepos}/antlib-svn/svnClientAdapter.jar"/>
<get dest="${user.home}/.ant/lib/svnant.jar" usetimestamp="1"
src="${url.ivyrepos}/antlib-svn/svnant.jar"/>
<get dest="${user.home}/.ant/lib/svnjavahl.jar" usetimestamp="1"
src="${url.ivyrepos}/antlib-svn/svnjavahl.jar"/>
</target>
If only svnant.jar is missing, everything works as expected. This is failing on a "class not found" error on the taskdef task if svnClientAdapter.jar is missing and on a "NoClassDefFoundError" when trying to use the task. As mentioned, I have tried where the retrieve.antlib-svn target is called as a dependency, as an 'ant' task and as a 'java' task (with fork).
This is Ant 1.7.0 with JDK 1.6.0_11 on Ubuntu 10.10 and RedHat ELS6. Detection/avoidance code removed for brevity. With debugging on, the only difference between the working invocation and the failed is the missing jar is included in ant's classpath, which I try to override in the taskdef task.
I wouldn't not mind spawning a new top-level ant call, but ivy.project.invoked-targets does not seem to be available in 1.7.0 and I have not figured out another way to call ant with the same starting targets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不会开箱即用:它与 Java 类加载器递归工作的事实有关,并且它们解决依赖关系,而不是 Ant 本身。
我为你感到抱歉,我认为如果不自己开发一个 Ant 扩展,这是不可能实现的,而且我对如何实现它一无所知。
It will not work out of the box : it has to do with the fact Java classloaders work recursively and THEY resolve the dependencies, not Ant itself.
I'm sorry for you, I think this is not achievable without developing yourself an Ant extension, and I don't have a single clue of how to make it.