2010-10-11 79 views
4

我已經安裝了Apache Ant並正確設置了Path,CLASS_PATH和ANT_PATH變量。當我在那裏的build.xml文件是我的項目文件夾中運行一個命令行罐子任務,我得到以下錯誤:執行Ant任務時出現問題

BUILD FAILED 

C:\Documents and Settings\TonyS\My Documents\My Workspace\code\build.xml: 32: 

The following error occurred while executing this line: 
jar:file:/C:/Documents%20and%20Settings/TonyS/My%20Documents/Ant/apache-ant-1.8.1/lib/ant.jar!org/apache/tools/ant/antlib.xml:37: Could not create task or type: componentdef. 

Ant could not find the task or a class this task relies upon. 

.... 

可以請別人給我的幫助,因爲這是推動我瘋了...

謝謝!

+0

Componentdef.class和Jar.class在ant.jar本身中。你的ant.jar是否損壞 - 大小是1.4Mb左右? – JoseK 2010-10-12 08:14:56

+0

我假設你談論的是PATH(不是'Path'),'CLASSPATH'(而不是'CLASS_PATH')和'ANT_HOME'(而不是'ANT_PATH')*環境變量*? – zb226 2017-04-11 11:52:53

+0

我不記得了,那已經快7年了。 – Anto 2017-04-11 12:43:40

回答

4

一種可能性是您可能在您的系統上安裝了另一個版本的ant,您的PATH指向它。

檢查什麼是ANT_HOME設置爲。

運行ant -version,看看它顯示了1.8.1

4

我有這個錯誤,並發現它是由在類路徑中的ant.jar的舊版本引起的。

1

添加以下配置在〜/ .bashrc

出口CLASSPATH =:$ JAVA_HOME/lib中/ dt.jar:$ JAVA_HOME/lib中/的tools.jar

不要忘記源〜/ .bashrc

希望對你有用!

1

你在你的環境中有重複的螞蟻。

我的情況是: 我使用1.9.7螞蟻,​​螞蟻卻-version給我1.7.1 我安裝WebLogic和它有1.7.1螞蟻,後改名MW_HOME,這個問題就消失了。

我在使用1.7.1測試junit時發現了這個問題。它顯示一個警告。

junit: 
    [junit] WARNING: multiple versions of ant detected in path for junit 
    [junit]   jar:file:/D:/wls12120/oracle_common/modules/org.apache.ant_1.7.1/lib/ant.jar!/org/apache/tools/ant/ 
Project.class 
    [junit]  and jar:file:/D:/apache-ant-1.7.1/lib/ant.jar!/org/apache/tools/ant/Project.class 
    [junit] Running HelloWorldTest