ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Jackson" <foamd...@gmail.com>
Subject Re: Classloader problems
Date Fri, 08 Jun 2007 02:15:46 GMT
Hi,

> I was supprised that the <taskdef> you described
> worked for scp, I think that you have removed the
> ant-jsch.jar from from $ANT_HOME/lib.

Yes as the classloader will find the ant-jsch.jar iin $ANT_HOME/lib
and try to load the jsch code from there.  I moved it to a different
location and <csp> worked fine - I expected the same behaviour with
<mail>, but instead I've had some problems.

> I tryed the following without removing ant-jsch.jar from
> $ANT_HOME/lib and got the expected build failure.
> build.xml:
> <project default="x">
>   <target name="x">
>     <property name="src.tools.dir" location="${user.home}/apps"/>
>     <path id="jsch.path">
>       <pathelement location="${src.tools.dir}/jsch/ant-jsch.jar"/>
>       <pathelement location="${src.tools.dir}/jsch/jsch-0.1.33.jar"/>
>     </path>
>     <taskdef
>       name="scp"
>       classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp"
>       classpathref="jsch.path"/>
>
>     <scp hello="world"/>
>   </target>
> </project>
>
> result:
> BUILD FAILED
> /work/reilly/learning/a/jsch/build.xml:11: taskdef A class needed by
> class org.apache.tools.ant.taskdefs.optional.ssh.Scp cannot be found:
> com/jcraft/jsch/UserInfo
>
>

> They are for <taskdef>.
>
> In ant1.7.0 only junit has been coded to allow the dependent classes
> to be defined in an embedded classpath.
> In ant1.7.1 this has been extended to the <script> family.
>
> The code involved uses classloader tricks that are not too
> easy to generalize to the other class dependent optional tasks.

It may be worth looking at though. It's strange to have one task work
as expected and another break when configuring them in the same way.
Principle of least surprise and all that

> See http://ant.apache.org/faq.html#delegating-classloader
> for a description of the problem.

I spent a while yesterday looking at that and reviewing what I could
do about it - I thought that since the scp task worked my moving all
the dependent jars and re-defining it, then the other tasks would too.

>
> In my build files, I use the excellent
> [antlib:net.jtools.classloadertask]classloader
> task:
>
> from http://enitsys.sourceforge.net/ant-classloadertask/
>     <typedef uri="antlib:net.jtools.classloadertask"
>              resource="net/jtools/classloadertask/antlib.xml">
>       <classpath>
>         <fileset
>           dir="${user.home}/tools/ant-classloader"
>                includes="*.jar"/>
>       </classpath>
>     </typedef>
>
>
>     <cl:classloader loader="project">
>       <classpath>
>         <fileset dir="${src.tools.dir}/jsch/" includes="js*.jar"/>
>       </classpath>
>     </cl:classloader>
>     <scp hello="world"/>
>

Thanks Peter, unless there's another work-around I will have to follow
your lead and use the same classloader task.

Kev

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message