cmd error: 'ANT' is not recognized as an i

2019-06-14 17:45发布

问题:

New here any just about anything else discussed on this site! Anyway, I'm trying to install ant on my machine but I'm getting an error from cmd:

'ant' is not recognized as an internal or external command, operable program or batch file

when running ant -version or ant -v. I'm using a Windows 7 machine (SP 1).

echo %PATH% command returns

C:\ProgramData\Oracle\Java\javapath;C:\Oracle11g\product\11.2.0\client_1\bin;C:\
Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Wi
ndows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPo
werShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Progra
m Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\I
ntel\Intel(R) Management Engine Components\IPT;C:\Program Files\TortoiseSVN\bin;
C:\Users\hat10024\Desktop\Eclipse\apache-ant-1.9.4\bin;C:\Program Files\nodejs\;
C:\Users\HAT10032\AppData\Roaming\npm;C:\Users\HAT10032\AppData\Local\Android\sd
k\platform-tools;C:\Users\HAT10032\AppData\Local\Android\sdk\tools;C:\apache-ant
-1.9.5\bin\;C:\Users\HAT10032\AppData\Roaming\npm

Actual value in Path System Variable is:

C:\ProgramData\Oracle\Java\javapath;C:\Oracle11g\product\11.2.0\client_1\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\TortoiseSVN\bin;C:\Users\hat10024\Desktop\Eclipse\apache-ant-1.9.4\bin;C:\Program Files\nodejs\;C:\Users\HAT10032\AppData\Roaming\npm;C:\Users\HAT10032\AppData\Local\Android\sdk\platform-tools;C:\Users\HAT10032\AppData\Local\Android\sdk\tools;%ANT_HOME%\bin\

I know this is ugly and long and shouldn't look that way from other solutions I've been reading but any help would be greatly appreciated! Thanks!!

回答1:

This can be done in 2 different ways:

1: From Command Prompt.

C:>set ANT_HOME=C:\Program Files\Ant Files\apache-ant-1.10.5

C:>set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181

C:>set PATH=%ANT_HOME%\bin;%JAVA_HOME%\bin

C:> ant -version

Apache Ant(TM) version 1.10.5 compiled on July 10 2018

2: By setting environment variables.

Right click on This PC > Properties > Advanced system settings > Environment Variables > User variables > New > Variable name:**ANT_HOME & for **Variable value:**C:\Program Files\Ant Files\apache-ant-1.10.5 > **OK.

Now goto System variables to add bin path. System variables > double click on Path >New > C:\Program Files\Ant Files\apache-ant-1.10.5\bin >New >C:\Program Files\Java\jdk1.8.0_181\bin>OK.

Now lets check whether it is installed correctly or not.

goto Command Prompt > and type ant -version.

C:> ant -version

Apache Ant(TM) version 1.10.5 compiled on July 10 2018

That's it. Let me know if still getting any difficulties.



回答2:

Go to apache ant and download the zip file.

Extract to folder where Tomcat or other Apache is in.

Go to system porperties >> Environmen Variables

In user variables click new >> Add

  • Variable Name: ANT_HOME

  • Variable Value: C:\Program Files\Apache Software Foundation\apache-ant-1.9.6

In the path add

  • C:\Program Files\Apache Software Foundation\apache-ant-1.9.6\bin

If u want to add two path then

  • "C:\Program Files\Apache Software Foundation\apache-ant-1.9.6\bin"; "C:\Program Files\Apache Software Foundation\apache-maven-3.3.9\bin"

Then go to cmd and type ant -version

Should work fine.



回答3:

First, you have to download ANT. Here is the link https://ant.apache.org/bindownload.cgi.

Then extract your downloaded file in C:\Program Files\Ant Folder where Ant Folder is the folder name where I have extracted.

Now you have to set environment variables.
Right click on This PC > Properties > Advanced system settings > Environment Variables > User variables > New > Variable name:ANT_HOME & for Variable value:C:\Program Files\Ant Files\apache-ant-1.10.5 > OK.

Now goto System variables to add bin path. System variables > double click on Path >New > C:\Program Files\Ant Files\apache-ant-1.10.5\bin > OK.
Now lets check whether it is installed correctly or not. goto Command Prompt > and type ant -version.
That's it. Let me know if still getting any difficulties.