将jar库文件添加到ant构建中

时间:2012-08-30 16:32:37

标签: java xml ant

我将commons-codec.1.2.jar添加到我的Java Build Path

    [javac] C:\Users\souzamor\workspace\tczip\src\tczip\Tczip.java:190: error: c
annot find symbol
    [javac]   mdEnc = new String( Hex.encodeHex( diges
t ));
    [javac]                       ^

这是我的build.xml文件:

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

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

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

    <target name="jar">
        <mkdir dir="build/jar" />
        <jar destfile="build/jar/Tczip.jar" basedir="build/classes">
            <manifest>
                <attribute name="Main-Class" value="tczip.ZipComparison" />
            </manifest>
        </jar>
    </target>

    <target name="run">
        <java jar="build/jar/Tczip.jar" fork="true" />
    </target>

</project>

我怎样才能将jar文件添加到build.xml文件中?我还有一个名为Java的{​​{1}}类来处理Tczip

MD5

我认为我没有正确地将其添加到我的jar文件中......我怎么能这样做?我对 [java] Processing: bhmcommonclient.zip [java] Exception in thread "main" java.lang.NoClassDefFoundError: org/apach mmons/codec/binary/Hex [java] at tczip.Tczip.digest(Unknown Source) [java] at tczip.Tczip.execute(Unknown Source) [java] at tczip.ZipComparison.showFiles(Unknown Source) [java] at tczip.ZipComparison.showFiles(Unknown Source) [java] at tczip.ZipComparison.showFiles(Unknown Source) [java] at tczip.ZipComparison.showFiles(Unknown Source) [java] at tczip.ZipComparison.showFiles(Unknown Source) [java] at tczip.ZipComparison.matchMD5(Unknown Source) [java] at tczip.ZipComparison.main(Unknown Source)

完全不熟悉

1 个答案:

答案 0 :(得分:4)

首先声明如下:

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

然后,在你的javac元素中,将它包含在类路径中,如下所示:

  <classpath>
    <path refid="external.classpath" />
  </classpath>