1

我是全新的Ant,我不知道如何classpathAnt. 我写了一个Java类来为我编写一些脚本,我想将它部署为一个taskin Ant. 该类commons-codec-1.2.jar用作外部库,在其他方面为我做一些UnicodeMD5任务。我已经发布了我的build.xml文件。

<?xml version="1.0" encoding="ISO-8859-1"?>
    <project name="TcZip" basedir="." default="jar">

    <property name="src.dir" value="src" />
    <property name="classes.dir" value="classes" />
    <property name="library.dir" value="library" />

    <path id="external.classpath">
        <pathelement location="${library.dir}/commons-codec-1.2.jar" />
    </path>

    <target name="clean" description="Delete all generated files">
    <delete dir="classes" />
    <delete file="TcZip.jar" />
    </target>

    <target name="compile" description="Compiles the task">
    <mkdir dir="${classes.dir}" />
    <javac srcdir="src" destdir="classes" />
        <classpath>
            <path refid="external.classpath" />
        </classpath>
    </target>

    <target name="jar" description="JARs the Task" depends="compile">
    <jar destfile="TcZip.jar" basedir="classes" />
    </target>

    <target name="use" description="Use the task" depends="jar">
    <taskdef name="tczip" classname="ZipComparision" classpath="${ant.project.name}.jar" />
    <tczip />
    </target>

</project> 

在我的task目录中,我有:

+task
 - build.xml
 - classes
 - library
 - src

libraryclasses包含该commons-codec-1.2.jar文件。但是,如build.xml文件中所示,我<property>library. 当我执行时,ant compile我得到:

compile:
    [javac] C:\workspace\task\build.xml:19: warning: 'includeantr
untime' was not set, defaulting to build.sysclasspath=last; set to false for rep
eatable builds
    [javac] Compiling 3 source files to C:\workspace\task\classes

    [javac] C:\workspace\task\src\Tczip.java:18: error: package o
rg.apache.commons.codec.binary does not exist
    [javac] import org.apache.commons.codec.binary.Hex;
    [javac]                                       ^
    [javac] C:\workspace\task\src\Tczip.java:190: error: cannot f
ind symbol
    [javac]     mdEnc = new String( Hex.encodeHex( digest ));
    [javac]                         ^
    [javac]   symbol:   variable Hex
    [javac]   location: class Tczip
    [javac] C:\workspace\task\src\Tczip.java:254: error: cannot f
ind symbol
    [javac]          mdEnc = new String( Hex.encodeHex( digest ));
    [javac]                              ^
    [javac]   symbol:   variable Hex
    [javac]   location: class Tczip
    [javac] 3 errors

BUILD FAILED
C:\workspace\task\build.xml:19: Compile failed; see the compiler
error output for details.

有人可以帮我吗?谢谢

4

1 回答 1

2

将指令替换location为.pathelementpath

于 2012-10-12T23:24:26.360 回答