surunzi
surunzi

Reputation: 43

How to execute ant using a batch file?

I have installed ant and it runs successfully in cmd. I know that when you want to use ant, you can enter the destination path and execute ant in command line. This works fine for me. But when I create a batch file to run ant in the destination path. It tells me that ant is not recognized as an internal or external command, operable program or batch file.

So here is what I want to know: how to execute ant in a batch file or is there another way to run it without entering cd command all the time?

Upvotes: 4

Views: 18930

Answers (4)

Be Kind To New Users
Be Kind To New Users

Reputation: 10063

Here is what I do:

@ECHO OFF
REM allows ant to be invoked from commandline without changing
REM windows configuration.  Place in %HOME%/bin and name ant.bat.
REM You will need to add %HOME%\bin to %PATH%, but once bin is
REM added to path you will not need to add it again for other commands.

SET ANT_HOME=C:\Users\Username\TOOLS\apache-ant-1.10.1

SET JAVA_HOME=C:\Program Files\Java\jdk1.8.0_112

SET PATH=%JAVA_HOME%\bin:%PATH%

"%ANT_HOME%\bin\ant" %*

I put that script in C:\Users\username\bin and name it ant.bat

I then modify the PATH once to add the bin folder. After that I can add any number of commands in bin without having to mess with changing path.

The %* passes whatever was passed on the commandline to ant. So then I can run ant like any other utility on the commandline or from another script like I would in bash.

Upvotes: 0

user4572280
user4572280

Reputation: 11

Have you tried setting your ANT_HOME in your batch script? e.g. (syntax may be slightly out of kilter)

SET ANT_HOME=C:\path\to\ant\directory
SET PATH=%PATH%\%ANT_HOME%\bin

Upvotes: 1

YeahIam
YeahIam

Reputation: 11

call ant -f %BUILDXML_LOC% -lib %ANTUNITLIB_HOME%

The above command must work. Just give it a try.

Where %BUILDXML_LOC% is the location where you have your build.xml file and %ANTUNITLIB_HOME% is the location where you have placed your ant-antunit-1.2.jar and additional jars required

Upvotes: 1

MC ND
MC ND

Reputation: 70923

"c:\directory\where\ant\is\ant" -buildfile "d:\directory\where\your\build.xml\is\"

Upvotes: 7

Related Questions