Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 117855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:24:08+00:00 2026-05-11T03:24:08+00:00

I want to use the FTP task in ant, and I have found the

  • 0

I want to use the FTP task in ant, and I have found the appropriate jar files and got everything working fine. I have put the jar files in a ‘libs’ directory alongside the other files used in the build. The only problem is that the user must run ‘ant -lib commons-net-ftp-2.0.jar’ to make a build; I would really prefer that it were possible to just run ‘ant’ with no arguments.

Reading the ant optional tasks intallation page, I see that there are five ways one can load up extra libraries in ant, and none of them are really what I’m looking for. I do not want to force the user to make any modifications to their system to run this task; it should be possible to just load it from the ‘libs’ directory inside of our product’s source folder. So that means setting the global CLASSPATH is also out (which is a bad idea anyways).

The last option, as noted in the documentation, is the preferred approach… loading the jarfiles individually from the build script itself. I have done this in the past with the ant-contrib tasks and JUnit, and would like to do that here, but I don’t see how I can accomplish this. The FTP task doesn’t support a nested classpath element, and I don’t know the XML resource I would need to load this library via a taskdef. How can I load the libraries from within ant?

Edit: In response to the answers and questions which have been posted here so far, I’m using ant 1.7.1. Making an ftp taskdef definitely does not work; that throws the following error:

BUILD FAILED /my/path/build.xml:13: taskdef class org.apache.tools.ant.taskdefs.optional.net.FTP cannot be found

Perhaps this is because the classname is wrong. How exactly do I find the classname I’m supposed to use if I only have a jarfile? It’s not documented anywhere, and I couldn’t find anything in the jar itself resembling that path.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:24:09+00:00Added an answer on May 11, 2026 at 3:24 am

    The problem you are having is due to the different class-loaders in use. The Commons Net classes must be loaded by the same class-loader that loads the FTP task. Because the FTP task is loaded by Ant on start-up, you need to add the Commons Net to Ant’s classpath so that it is loaded by the same class-loader. That’s why the documentation gives you 4 different ways to do this.

    I agree that none of them are ideal (the CLASSPATH environment variable being the worst). One way around this is to supply a shell script with your project that invokes Ant and passes the apporpriate -lib argument. You then get people to use this rather than invoking Ant directly. In fact, you could deviously name it ‘ant’ so that it gets run instead of the existing ‘ant’ on the path (this only works if the current directory is on the path, ahead of other directories).

    The fifth option in the documentation is great in theory. They finally fixed the class-loading problems in 1.7.0. Unfortunately, as you mention, nobody retro-fitted the FTP task to take a classpath. You could try submitting an enhancement request, but this won’t help in the short term.

    There is one other option, which isn’t any better than the others. Instead of making sure that the Commons Net classes are loaded by the class-loader that loads the FTP task, you could make sure that the FTP task is loaded by the class-loader that loads the Commons Net classes. To do this you have to remove the ant-commons-lib.jar file from the ‘lib’ directory of the Ant installation. This means that the FTP task won’t get loaded on start-up. This is actually why the optional tasks are broken up into so many separate JARs – so that they can be individually removed. Put this JAR file alongside the Commons Net JAR file so that it can be loaded at the same time. Then you can do something like this (I tried this and it works):

    <taskdef name='ftp'          classname='org.apache.tools.ant.taskdefs.optional.net.FTP'>   <classpath>     <pathelement location='${basedir}/lib/ant-commons-net.jar'/>     <pathelement location='${basedir}/lib/commons-net-2.0.jar'/>   </classpath> </taskdef> <ftp server='yourserver.com'      userid='anonymous'      password='blah'>   <fileset dir='somedirectory'/> </ftp> 

    But this is probably a worse option than just using the -lib switch (with or without a wrapper script). The only other thing I can think of is to try to find a third-party FTP task to use instead of the default one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use PowerShell to transfer files with FTP to an anonymous FTP
i want use some data from a website with web service. i have a
We have a powerbuilder application and we want use a scanner through this application
I'm working my way through 'head first design patterns' and want to use this
How to run local files on iphone? I use Windows 7 and i have
My pom.xml is running an Ant task to deploy a file using FTP. However,
My program runs smoothly but I want my files from ftp to be zip
I want to use SQLite database which is on FTP server without downloading it.
I have a bash script and I want to use ncftp to do something.
I want use this 1 for using Bar code or QR code scanner. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.