How To Run Ant FTP / Telnet / Rexec Task

BY ANGSUMAN CHAKRABORTY, GAEA NEWS NETWORKWEDNESDAY, NOVEMBER 2, 2005

Ant(javasoftware) from Apache Foundation is a popular build tool (often used successfully with other release management tasks) which replaces make.

“Apache Ant is aJava-based build tool. In theory, it is kind of like Make, but without Make’s wrinkles. ”

Included in Ant are optional tasks likeFTP& Telnet. For example the FTP Task allows you to communicate with FTP servers (get / put / list etc.).

Unfortunately they don’t work out of box and not well documented. In this article we will explain the whole procedure in six simple steps.

To use them follow the steps below:

  1. Downloadjakarta-oroandcommons-netlibrary.
    Note: The links above allow you to download the version I tested them with.
  2. Create a lib directory for your project if you have not already done so.
  3. Extract the jar file jakarta-oro*.jar fromjakarta-orolibrary you have downloaded and copy it to the lib directory you created.
    Note:

    • If you have downloaded from the links in step 1 then the exact file name isjakarta-oro-2.0.8.jar
    • Ensure that the file is copied to the lib directory and not to any of its sub-directories
  4. Extract the jar file commons-net*.jar file fromcommons-netlibrary you have downloaded and copy it to the lib directory.
    Note:

    • If you have downloaded from the links in step 1 then the exact file name iscommons-net-1.4.0.jar
    • Ensure that the file is copied to the lib directory and not to any of its sub-directories
  5. Add the ftp taskdef at the top:
    <taskdef name=”ftp” classname=”org.apache.tools.ant.taskdefs.optional.net.FTP”/>
  6. Add the appropriate task to your build.xml file. An example task to upload a directory is as follows:
    code
  7. Run Ant by including the lib directory in classpath. An example would be:
    ant -lib lib upload

    Note: I just had to include the lib directory to ensure all its jar files are automatically included.

Note:

  • The same procedure can be used to run Ant Telnet and RExec Tasks. Only the task name and parameters in build.xml file will change. Check the corresponding manuals for details.
  • I have promoted the use of lib directory (within project) to keep your jar files. This makes your jar files available only to your project. There are two other alternatives. First you can keep them in%ANT_HOME%/libdirectory. This makes them available to all projects for all users in that machine.
    You can also keep them in${user.home}/.ant/lib.

    The location of ${user.home}/.ant/lib is somewhat dependent on the JVM. On Unix systems ${user.home} maps to the user’s home directory whilst on recent versions of Windows it will be somewhere such as C:/Documents and Settings/username/.ant/lib.

    用Eclipse3.3+Ant1.7.0,在build.xml文件中使用ftp将包发到远程服务器上时总是出错,出错信息为:

    “Could not create type ftp due to java.lang.NoClassDefFoundError:

    org/apache/commons/net/ftp/FTPClientConfig”

    结果Google了N久,知道是少了两个包:commons-net-1.4.1.jar和jakarta-oro-2.0.8.jar

    把这两个包放到Eclipse的Ant的lib目录下,在Eclipse重新执行ant,问题依然存在。结果又Google了很久,最终,在一篇外国博文 中找到解决方法,原文如下

    “I had the same error message, but only in Eclipse (version 3.3).

    I did not get the error on command line. I had setup up ANT_HOME variable correctly and copied the jakarta-oro-2.0.8.jar and commons-net-1.4.1.jar to %ANT_HOME%/lib

    However it seems that the ANT Eclipse module does not automatically parse the %ANT_HOME%/lib directory for new jars and I had to add them manually

    preferences->Ant->Runtime, Classpath tab, Ant Home Entries -> Add External JARs...

    Then it worked. ”

你可能感兴趣的:(telnet)