0

我有两个班,ZipComparisonTczipTczip消化一个zip文件并处理其MD5, 同时ZipComparison搜索.zip条目,并比较.zip文件的两个不同版本以确定它们是否具有相同的内容。例如,在 apackage_a中有encodes.zip所以我想确定在 thepackage_bencodes.zip是否与.zippackage_a. 所以我处理MD5,如果它们匹配,那么我不需要复制MD5. build.xml如下:

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

    <path id="external.classpath">
        <pathelement location="src/commons-codec-1.2.jar"/>
    </path>

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

    <target name="compile">
        <mkdir dir="build/classes" />
        <javac srcdir="src/tczip" destdir="build/classes">
            <classpath>
                <path refid="external.classpath" />
             </classpath>
        </javac>
    </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>

所以我正在尝试创建一个ant构建文件。ZipComparison使用Tczip,但是当我编译时,执行是完美的,但是,当我这样做时,ant run我收到以下错误:

C:\Users\souzamor\workspace\tczip>ant run
Buildfile: C:\Users\souzamor\workspace\tczip\build.xml

run:
     [java] Processing: bhmcommonclient.zip
     [java] Exception in thread "main" java.lang.NoClassDefFoundError: org/apach
e/commons/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)
     [java] Caused by: java.lang.ClassNotFoundException: org.apache.commons.code
c.binary.Hex
     [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
     [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
     [java]     at java.security.AccessController.doPrivileged(Native Method)
     [java]     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
     [java]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
     [java]     ... 9 more
     [java] Java Result: 1

BUILD SUCCESSFUL
Total time: 4 seconds

我知道Tczip在舞台上丢失了compile,但是我怎样才能添加它,ZipComparison这样我就没有那种错误了?谢谢

4

1 回答 1

0

看起来该tczip.Tczip课程正在寻找来自Apache Commons Codec的课程。确保此 jar 与任何其他依赖项一起位于您的类路径中。请参阅此答案<path/>以了解在从 Ant元素创建 JAR 文件时如何将类路径添加到 JAR 清单中。

此外,您的 XML 不使用depends标签来确保compilejar执行run,这不是好的构建脚本实践。它应该真正使用depends

<target name="clean">
    <!-- ... -->
</target>

<target name="compile">
    <!-- ... -->
</target>

<target name="jar" depends="compile">
    <!-- ... -->
</target>

<target name="run" depends="jar">
    <!-- ... -->
</target>
于 2012-09-07T17:48:23.480 回答