2011-07-13 67 views
1

我在使用Ant找到並使用某些包時遇到問題。當我從命令行直接調用javac時,會發現並使用這些包。Ant問題包裝問題

.jar文件位於我的主目錄下的lib/java。這是我的類路徑: /home/bliskovs/lib/java/*:/home/bliskovs/vendor/cytoscape-v2.7.0/cytoscape.jar

這是我build.xml的相關章節:

<target name="compile"> 
    <javac srcdir="." debug="true"/> 
    <javac srcdir="tools/" debug="true"/> 
    <javac srcdir="core/" debug="true"/> 
    </target> 

我怎樣才能得到Ant來識別這些包?

回答

1

看看這個。

<property name="build.classes.dir" location="build/classes"/> 

<path id="compile.classpath"> 
    <fileset dir="lib"/> 
    <pathelement location="/home/bliskovs/vendor/cytoscape-v2.7.0"/> 
</path> 

<target name="compile" description="Compile src dir"> 
    <javac destdir="${build.classes.dir}" debug="true" includeantruntime="true"> 
    <src location="src"/> 
    <classpath refid="compile.classpath"/> 
    </javac> 
</target> 
1

定義javac任務的類路徑。依賴於CLASSPATH環境變量是一種不好的做法。對於項目的構建過程來說更是如此,它應該可以在不需要設置大量環境變量的情況下工作。如果您一次開始開發三個或四個項目,您將會明白爲什麼使用單個CLASSPATH變量是一個糟糕的主意。

請參閱http://ant.apache.org/manual/Tasks/javac.html瞭解如何在build.xml中定義類路徑並在javac任務中使用它。