21

I'm trying to build a project in Ant, using BuildFile (build.xml). Although ANT_HOME environment variable clearly exists and is set to the path where "ant.bat" is located, it always displays this error message. How to configure Ant properly to compile builds in Windows?

Thanks

SharpAffair
  • 5,558
  • 13
  • 78
  • 158
  • I was appending a ";" after ANT_HOME just like how we do for PATH. Because of this it was not working. Adding it here, someone may find it useful.. – codingbbq Nov 04 '15 at 09:21

9 Answers9

36

Actually ANT_HOME should NOT be set where ant.bat is located.

It should be set to the ant.bat parent directory.

E.g.

C:\apache-ant-1.8.1 <-- ANT_HOME
  |
  bin <-- this is where ant.bat lives.

As duffymo correctly pointed out the ANT_HOME/bin still must be on your PATH.

Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121
  • 5
    Note too that changing an environment variable like ANT_HOME won't be picked up by any command-prompt windows already open. If (like me) you had ANT_HOME pointing at the \bin directory where ant.bat lives, you also need to close your command-prompt window and open a new one. – Roger_S Jul 02 '13 at 15:09
  • @Roger_S just cost me a few hours... – Chagai Friedlander May 19 '20 at 17:09
28

ANT_HOME might be set, but that doesn't mean the path to /bin is in your PATH so the OS can find it.

Add ANT_HOME/bin to your PATH and the OS will be able to find ant.bat.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • 2
    if this doesn't work, go download the latest version. (not even sure what version i had...) +1 – Samuel Jun 22 '11 at 17:07
17

Just sharing my experience, using cd %ANT_HOME% can point out errors in setting the variable correctly.

  1. ANT_HOME should point to the parent directory, not the bin.
  2. Path should include %ANT_HOME%\bin
  3. The ant.bat file under bin is editable, it can be altered to print the current value for ANT_HOME for troubleshooting.
  4. A system reboot is probably required for the system variables to get updated.
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
msnewbit14
  • 171
  • 1
  • 2
  • Thank you a lot about (3)! Adding a log sentence to the ant.bat, and checking the current ant version helps a lot! – Hoàng Long Oct 13 '14 at 07:34
13

The ANT_HOME variable has to be a reference to the directory where the bin folder is found such as C:\Apps\apache-ant-1.8.4-bin\apache-ant-1.8.4\

The PATH reference can than be a reference to the ANT_HOME variable and the bin folder such as %ANT_HOME%\bin

example:

SET ANT_HOME=C:\Apps\apache-ant-1.8.4-bin\apache-ant-1.8.4\
SET PATH=%ANT_HOME%\bin
andr
  • 15,970
  • 10
  • 45
  • 59
1

I've had the same problem, and this is how I resolved it:

Open your ANT directory and check that all the ANT files exist (like directories for bin,lib,etc...) I found my ANT directory was abnormal, just bin was there, the others like lib were missing. (I'm not sure what caused this)

If you have missing files/directories, unzip the apache-ant-1.9.4-bin.zip again, and make sure all the files exist.

kristian
  • 22,731
  • 8
  • 50
  • 78
Luke
  • 83
  • 6
1

ANT_HOME should be set to the directory where ant is installed. e.g.

If your ant installation is located at: C:\tools\apache-ant

Your ANT_HOME should be set: set ANT_HOME=C:\tools\apache-ant at the System Environment settings and not User Environment Settings

Community
  • 1
  • 1
naikus
  • 24,302
  • 4
  • 42
  • 43
0

If you are using Bamboo, make sure that the ant path in Bamboo setting is the same as your ANT_HOME.

TonySalimi
  • 8,257
  • 4
  • 33
  • 62
0

I had the same problem and none of these solutions worked, so i simply deleted my ANT_HOME from enviroment variables, restarted my PC and I was all set to go

Sagar Devanga
  • 2,815
  • 27
  • 30
0

Check your existing PATH that may already included. Ant will not work if path is duplicated.

james
  • 1,967
  • 3
  • 21
  • 27