使用Ant Builder将文件复制到远程位置

时间:2014-06-30 07:16:50

标签: java ant build

请帮助找出我无法将jar文件复制到ftp位置的原因。它将C:作为远程位置root.Please帮助纠正错误。

build.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project>

    <target name="clean">
        <delete dir="D:/build"/>
    </target>

    <target name="compile">
        <mkdir dir="D:/build/classes"/>
        <javac srcdir="src" destdir="D:/build/classes"/>
    </target>

    <target name="jar">
        <mkdir dir="D:/build/jar"/>
        <jar destfile="D:/build/jar/ffjar.jar" basedir="D:/build/classes">
            <manifest>
                <attribute name="Main-Class" value="test.ant.Test"/>
            </manifest>
        </jar>
    </target>   

    <target name="run">
        <java jar="D:/build/jar/ffjar.jar" fork="true"/>
    </target>


    <target name="deploy">      
        <ftp server="ip"
           remotedir="/home/ecnet"
           userid="user"
           password="pass"
           depends="yes">
           <fileset dir="/home/ecnet/ffjar.jar"/>
        </ftp>
      </target>

</project>

输出

Buildfile: C:\Users\Joseph.M\WorkPlace_Struts2\CheckAnt\build.xml
clean:
   [delete] Deleting directory D:\build
compile:
    [mkdir] Created dir: D:\build\classes
    [javac] C:\Users\Joseph.M\WorkPlace_Struts2\CheckAnt\build.xml:11: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 1 source file to D:\build\classes
jar:
    [mkdir] Created dir: D:\build\jar
      [jar] Building jar: D:\build\jar\ffjar.jar
run:
     [java] Hello Ant World
deploy:
      [ftp] sending files

BUILD FAILED
C:\Users\Joseph.M\WorkPlace_Struts2\CheckAnt\build.xml:34: C:\home\ecnet\ffjar.jar does not exist.

Total time: 7 seconds

1 个答案:

答案 0 :(得分:1)

问题在于这一行

<fileset dir="/home/ecnet/ffjar.jar"/>

我相信您的Ant安装在C:驱动器中,因此它正在尝试相应地解析此路径。您需要将此路径更改为实际路径,如:

<fileset dir="D:/build/jar/ffjar.jar"/>

我建议创建一个属性文件并在那里定义所有路径并使用变量而不是硬编码build.xml中的所有路径

希望这有帮助。