Loading ant libraries after download
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 s开发者_Python百科eem to be available in 1.7.0 and I have not figured out another way to call ant with the same starting targets.
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.
精彩评论