0

我添加commons-codec.1.2.jar到我的 Java 构建路径

    [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名为Tczipwhich processes的类MD5

 [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)

我认为我没有将其正确添加到我的 jar 文件中……我该怎么做?我完全陌生Ant

4

1 回答 1

5

首先像这样声明它:

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

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

  <classpath>
    <path refid="external.classpath" />
  </classpath>
于 2012-08-30T16:36:05.703 回答