今天終於解決了一個延宕多時的問題 --> 在我的機器上始終無法執行ANT!
C:\Documents and Settings\Administrator>ant
這個時候不應有 Files\Apache。
上Google找了很多次也找了很久始終找不到答案(居然有Google找不到的東西!),
在百般無奈下只好再度把manual翻出來看,終於在仔細研讀後看到了這麼一段話
Windows Note: | |
The ant.bat script makes use of three environment variables - ANT_HOME, CLASSPATH and JAVA_HOME. Ensure that ANT_HOME and JAVA_HOME variables are set, and that they do not have quotes (either ' or ") and they do not end with \ or with /. CLASSPATH should be unset or empty. |
原來是我先前設定的CLASSPATH造成ANT無法執行,於是趕緊在ant.bat的開頭加上
set CLASSPATH=
經測試後終於解決了擱置超過半年的疑案!
C:\Documents and Settings\Administrator>ant這個故事告訴我們人要在走投無路而且有只能靠自己的覺悟時才會認真看manual。。。
Buildfile: build.xml does not exist!
Build failed
3 comments:
你好,我是在Google "CLASSPATH should be unset or empty"時,找到你的Blog。同樣的問題我也發生過,但是我解決的方式不一樣,對問題的成因也有不一樣的看法,跟你分享一下。
我發現的問題是我的%JAVA_HOME%與%ANT_HOME%設為"c:\program files\jdk"and"c:\program files\Ant",請注意路徑有用" "包起來。因為在家裡Vista的環境下,Program Files中間的空白會造成指令辨認錯誤,所以我在公司的XP也是作同樣的設定。但是Ant manual也有講"Ensure that ANT_HOME and JAVA_HOME variables....do not have quotes (either ' or ") ",所以不能用" ",又要確保指令能被正確辨認,我把"c:\program files\..."改成c:\progra~1\..,這是以前在95,98環境學到的,XP上試過也成功了,Vista就不知道了。
"CLASSPATH should be unset or empty"這一行令我感到很懸疑,如果系統真的沒有設CLASSPATH很多東西都不能用,但是我也沒也因為CLASSPATH不是空的,而遇到任何問題。
我想用ant的原因之一是要自行定義dependency,在完全遵循這樣的理念下,classpath應該是要在build.xml裡面定義,而不需要設死在環境變數中,以上只是我個人的臆測~
manual裡是這麼解釋的:
you can save yourself a lot of time and frustration by following some simple steps.
1. Do not ever set CLASSPATH. Ant does not need it, it only causes confusion and breaks things.
2. If you ignore the previous rule, do not ever, ever, put quotes in the CLASSPATH, even if there is a space in a directory. This will break Ant, and it is not needed.
3. If you ignore the first rule, do not ever, ever, have a trailing backslash in a CLASSPATH, as it breaks Ant's ability to quote the string. Again, this is not needed for the correct operation of the CLASSPATH environment variable, even if a DOS directory is to be added to the path.
4. You can stop Ant using the CLASSPATH environment variable by setting the -noclasspath option on the command line. This is an easy way to test for classpath-related problems.
看來問題還是出在CLASSPATH,因為我用%JAVA_HOME% and %ANT_HOME%去寫CLASSPATH,所以就把""帶了過去。
剛剛看了一下Ant.bat的內容,似乎ver1.8會自動重設CLASSPATH。
Post a Comment