Search code examples
antbatch-filecruisecontrol

using ant script to exceute a batch file


this is a batch file that i have. It is located in C:\Work\6.70_Extensions\Lab Tools\ folder.

ANT.BAT:

set CLASSPATH=%CLASSPATH%;.;c:\JavaMail\javamail-1.3\mail.jar;c:\JavaMail\javamail-1.3\mailapi.jar;c:\JavaMail\javamail-1.3\pop3.jar;c:\JavaMail\javamail-1.3\smtp.jar;c:\JavaMail\jaf-1.0.2\activation.jar
CALL "C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat"
@echo on

%ANT_HOME%\bin\ant -logger org.apache.tools.ant.listener.MailLogger -q -buildfile "Master Build.xml"
pause

along with ant.bat, i have a Master Build.xml file located inside the same folder.

When i double click on ant.bat, it will execute the Master Build.xml ant script properly.

However, whenever i try to use another application to open the batch file's absolute path, it always state that Master Build.xml file does not exist!

I tried to open the absolute path using both console application and another ANT Script(via Cruisecontrol framework) but both gives the same error. What is the error here?

for your information here is what ive done with cruisecontrol:

  1. create config.xml (to set intervals for builds)
  2. create nightbuild.xml (so that config.xml will go into it to perform required tasks)
  3. nightbuild.xml will run several console applications to sort files, checkout files from version control etc
  4. lastly, nightbuild.xml will execute ant.bat file to execute the build

These files, config.xml and nightbuild.xml are found in C:\build


Solution

  • When you execute from a directory other than the one containing Master Build.xml, Ant will fail to find the build file, which it expects to be in the current working directory.

    You could set an additional environment variable to specify the path to the build file, e.g.

    %ANT_HOME%\bin\ant -buildfile "%MASTER_BUILD%\Master Build.xml"
    

    If you set your variable to an absolute path (e.g. C:\Work\6.70_Extensions\Lab Tools) then it will always work. If you use a relative path (e.g. .\Lab Tools), then it will only work if executed from the relative root dir.

    (BTW, life will probably be easier if you use buildfiles without spaces in their names, e.g. master_build.xml rather than Master Build.xml).