Windows上的FTP自动化无法运行

时间:2015-10-30 06:02:02

标签: xml eclipse ant ftp

我的脚本如下:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Getting from FTP" default="info" basedir=".">

   <target name="info">
    <property name="testfolder" value="My\Test\Folder\Path" />
      <echo>Hello World - Welcome to Apache Ant!</echo>
      <echo>Java version: ${ant.java.version}</echo>
      <echo>Ant Version: ${ant.version}</echo>
      <echo>Base Dir: "${basedir}"</echo>
      <mkdir dir="${testfolder}\ant-test"/>
       <classpath>
            <fileset dir="${basedir}" includes="*.jar" />
      </classpath>
      <ftp action="get"
        server="my.server.location.somewhere"
        userid="username"
        password="password"
        remotedir="/path/on/my/server"
        verbose="yes"
        >
        <fileset dir="${testfolder}\ant-test">
            <include name="**\*" />
        </fileset>
    </ftp>
   </target>
</project>

我在eclipse上编写文件,并在我的工作区文件夹中放置了commons-net-3.3.jar文件。在这里,它是AutomateDownload。但是,当我运行脚本时,我收到此错误:

Buildfile: mydrive\on_server\my_workspace\ftpauto\AutomateDownload\build.xml
info:
     [echo] Hello World - Welcome to Apache Ant!
     [echo] Java version: 1.8
     [echo] Ant Version: Apache Ant(TM) version 1.9.4 compiled on April 29 2014
     [echo] Base Dir: "mydrive\on_server\my_workspace\ftpauto\AutomateDownload"

BUILD FAILED
mydrive\on_server\my_workspace\ftpauto\AutomateDownload\build.xml:11: Problem: failed to create task or type classpath
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

它在我的本地机器上运行,因为我将.jar文件保存在ANT_HOME的lib文件夹中。它工作得很好。但是现在当我在我的服务器机器上运行它时,我遇到了错误。任何人都可以帮我解决我遇到的问题,你能否详细告诉我,究竟是什么问题?为什么我会遇到这种问题?谢谢:))

1 个答案:

答案 0 :(得分:1)

没有名为“classpath”的ANT任务。这就是ANT抛出错误的原因。

我怀疑你要做的是创建路径引用?

  <path id="proj.path">
    <fileset dir="${basedir}" includes="*.jar" />
  </path>

但是...... ftp 任务不支持类路径引用...因此,建议您最好将依赖项jar放在“$ HOME / .ant / lib”目录中。

我使用的技巧是使用特殊的ANT目标下载和安装依赖项:

<target name="install-dependencies">
    <mkdir dir="${user.home}/.ant/lib"/>
    <get dest="${user.home}/.ant/lib/commons-net.jar" src="http://search.maven.org/remotecontent?filepath=commons-net/commons-net/3.3/commons-net-3.3.jar"/>
</target>

目标只需要在每台构建计算机上运行一次

$ ant install-dependencies