Two Laptop Bag*
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant problem" Watch "Ant problem" New topic
Author

Ant problem

dave chan
Greenhorn

Joined: May 04, 2005
Posts: 6
Hi all,

I have the same problem for both Ant 1.6.2 and 1.6.3, hope someone can help me out. I
1) downloaded the ant zip file (binary distributions)
2) unzipped it to "c:\ant"
3) cd to "c:\ant\bin"
4) type "ant -version"

I got error message below:
Buildfile: build.xml does not exist!
Build failed

It seems the command line just don't want to take any argument after "ant". Non matter what argument that I put after the "ant" (eg, "ant -help", "ant -diagnostics"), it always displays "Buildfile: build.xml does not exist!". If I put the build.xml on "c:\ant\bin", it runs just fine... Anyone can help??

The OS of my machine is Win2k with service pack 4. thanks.
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

Is it possible that you did not specify the '-' before the keyword


when you launch ant, it will look for your build script (build.xml by default) where you define your build strategy : clean, compile,test, createJar, javadoc...

First, you should define your environment variables to point to ant, and while you're at it, java, path and classpath :

SET ANT_HOME=utils\ant
SET JAVA_HOME=utils\jdk1.4.2
SET PATH=%JAVA_HOME%\bin;%ANT_HOME%\BIN;%PATH%
SET CLASSPATH=%JAVA_HOME%\lib;.;%CLASSPATH%

Now you can launch ant from wherever you are by typing "ant compile".
Typing this will go through the build.xml you wrote and execute the target "compile". Your build.xml should be in the current directory when you launch ant.

If you want, you can specify another filename for your buildscript :

Hope this helps,
Alex
[ May 05, 2005: Message edited by: Alex Turcot ]
dave chan
Greenhorn

Joined: May 04, 2005
Posts: 6
Hi,

First of all thanks for reply.
Actually, I already set all the system path as well as JAVA_HOME/ANT_HOME. I ran the "echo" command and confirmed they were corrected.

I am sure I include the "-" with the command "ant -version" that I typed. As I state, it just ignores the second argument that I type on the command line. It doesn't matter if I type "ant -version" or "ant -help", it always return the error message "Buildfile: build.xml does not exist!". If I create a sample "build.xml", everything run just fine.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

Your you don't have an "ANT.BAT" file in your path covering up the %ANT_HOME$\bin\ant program? I had no problems with Ant 1.5 or 1.6.2.


Customer surveys are for companies who didn't pay proper attention to begin with.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Now I'm not sure what you've done. Your original steps are not what the Ant manual - installation instructions say to do. Since you insist everything is correct and don't show us the output how are we to help? We can point to instructions and troubleshooting information.

From Ant "Having Problems" page:

Also, we highly recommend that you run Ant with an empty CLASSPATH. If any other version of Ant can be loaded from the CLASSPATH, many types of errors may happen because of incompatible classes being loaded.

See the FAQ for some examples, but many other problems are a result of an old version of Ant on your system as well.
dave chan
Greenhorn

Joined: May 04, 2005
Posts: 6
Hi All,

I comment out the first line of the ant.bat and dump the result of the command "ant -version" as below. I really don't know what happen here. I try to install ANT on my friend's pc and everything's cool. Any suggestion?


=============================================================
C:\temp>REM @echo off

C:\temp>REM Copyright 2001,2004-2005 The Apache Software Foundation

C:\temp>REM

C:\temp>REM Licensed under the Apache License, Version 2.0 (the "License");

C:\temp>REM you may not use this file except in compliance with the License.

C:\temp>REM You may obtain a copy of the License at

C:\temp>REM

C:\temp>REM http://www.apache.org/licenses/LICENSE-2.0

C:\temp>REM

C:\temp>REM Unless required by applicable law or agreed to in writing, software

C:\temp>REM distributed under the License is distributed on an "AS IS" BASIS,

C:\temp>REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

C:\temp>REM See the License for the specific language governing permissions and

C:\temp>REM limitations under the License.

C:\temp>if exist "\antrc_pre.bat" call "\antrc_pre.bat"

C:\temp>if "Windows_NT" == "Windows_NT"

C:\temp>if "Windows_NT" == "WINNT"

C:\temp>rem C:\ANT\bin\ is expanded pathname of the current script under NT

C:\temp>set DEFAULT_ANT_HOME=C:\ANT\bin\..

C:\temp>if "C:\ANT" == "" set ANT_HOME=C:\ANT\bin\..

C:\temp>set DEFAULT_ANT_HOME=

C:\temp>set _USE_CLASSPATH=yes

C:\temp>rem Slurp the command line arguments. This loop allows for an unlimited number

C:\temp>rem of arguments (up to the command line limit, anyway).

C:\temp>set ANT_CMD_LINE_ARGS=-version

C:\temp>if ""-version"" == """" goto doneStart

C:\temp>shift

C:\temp>if """" == """" goto doneStart

C:\temp>rem find ANT_HOME if it does not exist due to either an invalid value passed

C:\temp>rem by the user or the -version problem on Windows 9x

C:\temp>if exist "C:\ANT\lib\ant.jar" goto checkJava

C:\temp>set _JAVACMD=

C:\temp>if "C:\Program Files\Java\jdk1.5.0_03" == "" goto noJavaHome

C:\temp>if not exist "C:\Program Files\Java\jdk1.5.0_03\bin\java.exe" goto noJavaHome

C:\temp>if "" == "" set _JAVACMD=C:\Program Files\Java\jdk1.5.0_03\bin\java.exe

C:\temp>goto checkJikes

C:\temp>if not "" == "" goto runAntWithJikes

C:\temp>if "yes" == "no" goto runAntNoClasspath

C:\temp>if not "C:\Program Files\IBM\IBM CICS Transaction Gateway\Classes\CTGCLIENT.JAR;C:\Program Files\IBM\IBM CICS Transaction Gateway\Classes\CTGSERVER.JAR;C:\Program Files\IBM\IBM CICS Transaction Gateway\Classes\CICSJ2EE.JAR;C:\Program Files\IBM\IBM CICS Transaction Gateway\Classes\CTGSAMPLES.JAR;C:\Program Files\IBM\WebSphere MQ\Java\lib\providerutil.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mqjms.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\ldap.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\jta.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\jndi.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\jms.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\connector.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\fscontext.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mq.jar;C:\oracle\ora90\jdbc\lib\ojdbc14.jar;C:\PROGRA~1\IBM\SQLLIB\java\db2java.zip;C:\PROGRA~1\IBM\SQLLIB\java\db2jcc.jar;C:\PROGRA~1\IBM\SQLLIB\java\sqlj.zip;C:\PROGRA~1\IBM\SQLLIB\java\db2jcc_license_cisuz.jar;.;C:\PROGRA~1\IBM\SQLLIB\java\" == "" goto runAntWithClasspath

C:\temp>"C:\Program Files\Java\jdk1.5.0_03\bin\java.exe" -classpath "C:\ANT\lib\ant-launcher.jar" "-Dant.home=C:\ANT" org.apache.tools.ant.launch.Launcher -cp "C:\Program Files\IBM\IBM CICS Transaction Gateway\Classes\CTGCLIENT.JAR;C:\Program Files\IBM\IBM CICS Transaction Gateway\Classes\CTGSERVER.JAR;C:\Program Files\IBM\IBM CICS Transaction Gateway\Classes\CICSJ2EE.JAR;C:\Program Files\IBM\IBM CICS Transaction Gateway\Classes\CTGSAMPLES.JAR;C:\Program Files\IBM\WebSphere MQ\Java\lib\providerutil.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mqjms.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\ldap.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\jta.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\jndi.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\jms.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\connector.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\fscontext.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mq.jar;C:\oracle\ora90\jdbc\lib\ojdbc14.jar;C:\PROGRA~1\IBM\SQLLIB\java\db2java.zip;C:\PROGRA~1\IBM\SQLLIB\java\db2jcc.jar;C:\PROGRA~1\IBM\SQLLIB\java\sqlj.zip;C:\PROGRA~1\IBM\SQLLIB\java\db2jcc_license_cisuz.jar;.;C:\PROGRA~1\IBM\SQLLIB\java\" -version
Buildfile: build.xml does not exist!

C:\temp>goto end

C:\temp>set _JAVACMD=

C:\temp>set ANT_CMD_LINE_ARGS=

C:\temp>if "Windows_NT" == "Windows_NT"

C:\temp>if "Windows_NT" == "WINNT"

C:\temp>if exist "\antrc_post.bat" call "\antrc_post.bat"

====================================================================
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Did you try unsetting your classpath before running ant -version?

set classpath=

If with 1.6.3 I set my classpath to what is shown in your post I get your error of "build.xml does not exist!":


C:\_tools\apache-ant-1.6.3\bin>"c:\bea813\jdk142_04\bin\java.exe" -classpath "C:\_tools\apache-ant-1.6.3\lib\ant-launcher.jar" "-Dant.
home=C:\_tools\apache-ant-1.6.3" org.apache.tools.ant.launch.Launcher -cp "C:\Program Files\IBM\IBM CICS Transaction Gateway\Classes\C
TGCLIENT.JAR;C:\Program Files\IBM\IBM CICS Transaction Gateway\Classes\CTGSERVER.JAR;C:\Program Files\IBM\IBM CICS Transaction Gateway\
Classes\CICSJ2EE.JAR;C:\Program Files\IBM\IBM CICS Transaction Gateway\Classes\CTGSAMPLES.JAR;C:\Program Files\IBM\WebSphere MQ\Java\li
b\providerutil.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mqjms.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\ldap.jar;C:\
Program Files\IBM\WebSphere MQ\Java\lib\jta.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\jndi.jar;C:\Program Files\IBM\WebSphere MQ\J
ava\lib\jms.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\connector.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\fscontext.jar;C:\Pr
ogram Files\IBM\WebSphere MQ\Java\lib\com.ibm.mq.jar;C:\oracle\ora90\jdbc\lib\ojdbc14.jar;C:\PROGRA~1\IBM\SQLLIB\java\db2java.zip;C:\PR
OGRA~1\IBM\SQLLIB\java\db2jcc.jar;C:\PROGRA~1\IBM\SQLLIB\java\sqlj.zip;C:\PROGRA~1\IBM\SQLLIB\java\db2jcc_license_cisuz.jar;.;C:\PROGRA
~1\IBM\SQLLIB\java\" -version
Buildfile: build.xml does not exist!
Build failed
dave chan
Greenhorn

Joined: May 04, 2005
Posts: 6
thanks for your suggestion.
It seems the string/value of the classpath is too long on my machine. I remove some of the value and then add "%JAVA_HOME%\bin" to the classpath, it runs fine now.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
There are a variety of things that can go wrong with ant when your classpath is set in your environment. I unset mine with 1.6.x and set up the necessary classpaths in the build.xml. Assuming you were going to have your classpath set you shouldn't need %JAVA_HOME%\bin included, that's not a place where classes live.

Ant "Having Problems" page:

Also, we highly recommend that you run Ant with an empty CLASSPATH. If any other version of Ant can be loaded from the CLASSPATH, many types of errors may happen because of incompatible classes being loaded.
dave chan
Greenhorn

Joined: May 04, 2005
Posts: 6
so what should I do with my classpath?

I remove the "%JAVA_HOME\bin" and run the command "ant -version", it complains the missing of the "build.xml" file. I, however, run the command "ant -version -noclasspath", it displays the ant version information correctly. thanks.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
You can specify your classpath in your build.xml.

See Path-like structures in the ant manual's Writing a simple build file.

Scroll down to the bottom of that page, to the references section to see example use of a "named" classpath in the javac task.
[ May 16, 2005: Message edited by: Carol Enderlin ]
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Dave Chan
Here is an example for set your classpath

 
jQuery in Action, 2nd edition
 
subject: Ant problem
 
Similar Threads
Issue in making axis2.war
ant pkg won't work for installing I2P
ant installation problems
Glassfish Installation Help
build.xml does not exist !