This happens when the Environment Variable JAVA_HOME is not set, or points to the wrong directory. You can see the value that Ant has by running the command:
ant -diagnostics
And looking for the line that shows java.home
. If you have grep
installed then you can simple run:
ant -diagnostics | grep java.home
To fix the issue, set the JAVA_HOME
Environment Variable to the JDK directory. While setting the variable differs slightly between *nix and Windows, the rest works the same on all operating systems. So it doesn't matter if you use the GUI that Windows provides, or the set
or setx
commands, as long as the value is set prior to calling ant
(if you've set it globally then it must exist before you open the shell/terminal window).
After setting JAVA_HOME
you can run ant -version
, for example, and get the result, e.g.
Apache Ant(TM) version 1.10.8 compiled on May 10 2020