2012-08-30 71 views
0

我加commons-codec.1.2.jar到我的Java構建路徑添加的jar庫文件到Ant構建

[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類稱爲Tczip哪些進程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

+0

我將創建一個' jar'文件,這將是一個庫文件...但編譯我需要添加另一個'jar'到我的路徑... – cybertextron

+0

請參閱:http://stackoverflow.com/questions/722774/getting-ant-javac -to-recognized-a-classpath – davidmontoyago

回答

4

首先這樣聲明它:

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

然後,你的javac元素中,包括在類路徑是這樣的:

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

同樣的輸出:'import org.apache.commons.codec.binary.Hex' – cybertextron

+0

有一個錯字,我是指1.1,現在我修好了。確保$ {lib.dir}將您引導至jar所在的正確位置。 –

+0

dan我會更新我的問題...... – cybertextron