ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Reilly" <peter.kitt.rei...@gmail.com>
Subject Re: Classloader problems
Date Thu, 07 Jun 2007 10:23:02 GMT
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.

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



On 6/7/07, Kevin Jackson <foamdino@gmail.com> wrote:
> Hi all,
>
> For obscure reasons, I have to redefine the core email task using a taskdef.
> This is my build file:
> <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"/>
>
> <taskdef name="sshexec"
> classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"
> classpathref="jsch.path"/>
>
> <taskdef name="mail"
>                 classname="org.apache.tools.ant.taskdefs.email.EmailTask">
>         <classpath>
>           <pathelement location="${src.tools.dir}/mail/ant-javamail.jar"/>
>           <pathelement location="${src.tools.dir}/mail/mail.jar"/>
>         </classpath>
> </taskdef>
>
> Now the strange thing is that thescp & sshexec tasks report that they
> have been over-ridden by the new definitions, and with -debug enabled
> I can see the correct classes being loaded.  The mail task however
> just reports ' Class org.apache.tools.ant.taskdefs.email.EmailTask
> loaded from parent loader (parentFirst)'.
>
> Then finally it fails with ClassNotFoundException.  This means that
> the <classpath> is ignored for the mail taskkdef, but is used
> correctly for the scp/sshexec taskdefs.
>
> I would think it would make sense to treat all taskdefs & classpaths equal...
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.

>
> I cannot copy the jars into ~/.ant/lib, or $ANT_HOME/lib, and I cannot
> rely on a CLASSPATH variable or an external calling script.  The only
> way I can make what I want to do work is via the taskdefs which honour
> the <classpath> or classpathref.  Does anyone know how to work around
> this?

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

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"/>


Peter

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

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


Mime
View raw message