3

I would like to specify the classpath for an fpt task directly in my Ant Build script. I tried the following:

<target name="ftp-upload" depends="build-html">     
   <echo message="Ftp upload started with user ${user}" />
<ftp verbose="yes" 
            remotedir="${ftp.dir}" 
    server="${server}"
            userid="${user}" 
    password="${password}" 
    depends="yes">
      <fileset dir="${mystuff.dir}/.." />
     <classpath refid="build.classpath" />
</ftp>
</target>

and

<target name="ftp-upload" depends="build-html">     
 <echo message="Ftp upload started with user ${user}" />
<ftp verbose="yes" 
            remotedir="${ftp.dir}" 
    server="${server}"
            userid="${user}" 
    password="${password}" 
    depends="yes"
            classpathref="build.classpath"
     >
      <fileset dir="${mystuff.dir}/.." />
</ftp>
</target>

The first approach gives me the following error message:

Could not create type ftp due to java.lang.NoClassDefFoundError:      org/apache/commons/net/ftp/FTPClientConfig

The second approach gives me the following error message:

ftp doesn't support the "classpathref" attribute

Is it possible to set the classpath in the build script for the ftp tasks or do I have to do it outside the build script on my server? Would be nice to have the build script self-contained.

Solution:

Just re-define the ftp task with your classpath reference:

<taskdef name="ftp" classname="org.apache.tools.ant.taskdefs.optional.net.FTP">
 <classpath>
    <pathelement location="\lib\commons-net-1.4.0.jar"/>
 </classpath>
</taskdef>
vogella
  • 24,574
  • 4
  • 29
  • 26

1 Answers1

1

Have you tried the solution commented at How to load an optional task into ant without -lib or global installation? ?

I had a similar problem some time ago and I solved it adding a new classloader.

Regards

Community
  • 1
  • 1