简体   繁体   中英

How can I specify the classpath in the build file of an ftp tasks

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM