windows 'ant' 未被识别为内部或外部命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9262712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:13:27  来源:igfitidea点击:

‘ant’ is not recognized as an internal or external command

windowsantpath

提问by user1152440

I have the same issue as this user: ant - not recognized as an internal

我和这个用户有同样的问题:蚂蚁 - 不被识别为内部

however unfortunately none of the solutions have worked for me in that post or any other. I've also looked at other commands not recognized and specifically adding a path variable. The procedure I am using is as follows:

然而不幸的是,在那篇文章或任何其他文章中,没有一个解决方案对我有用。我还查看了其他无法识别的命令,并专门添加了路径变量。我使用的程序如下:

Extract to a desired installation directory, e.g. C:\apache-ant
Create an ANT_HOME environment variable`

Open System Properties -> Advanced -> Environment Variables
Create a new system variable
    Variable name: ANT_HOME
    Variable value: C:\apache-ant 

Add %ANT_HOME%\bin directory to the PATH system variable

Open System Properties -> Advanced -> Environment Variables
Under system variables, select PATH and append ;%ANT_HOME%\bin
    e.g. %SystemRoot%\system32;%SystemRoot%;%JAVA_HOME%\bin;%ANT_HOME%\bin

Verify that ANT is installed.

Open a new command window and type:
C:\>ant -v`

In my case the Variable value is C:\apache-ant\apache-ant-1.8.2.

在我的情况下,变量值是C:\apache-ant\apache-ant-1.8.2.

My exact path variable is %SystemRoot%\system32;%SystemRoot%;%JAVA_HOME%\bin;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%JAVA_HOME%\bin;%ANT_HOME%\binwhich doesn't have any spaces between semicolons.

我的确切路径变量是%SystemRoot%\system32;%SystemRoot%;%JAVA_HOME%\bin;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%JAVA_HOME%\bin;%ANT_HOME%\bin分号之间没有任何空格。

However testing the ant installation does not work, the picture below is what I'm experiencing:

但是测试 ant 安装不起作用,下图是我遇到的情况:

enter image description here

在此处输入图片说明

I have tried restarting on numerous occasions to no avail. I have run out of ideas, so if anyone has any any information would be helpful. Thanks!

我曾多次尝试重新启动都无济于事。我的想法已经用完了,所以如果有人有任何信息会有所帮助。谢谢!

EDIT

编辑

Posted results of dir:

dir的发布结果:

enter image description here

在此处输入图片说明

回答by Adam Bruss

ANT_HOMEis not being resolved. Change %ANT_HOME%\binin the Path system environment variable to c:\apache-ant\apache-ant-1.8.2\bin.

ANT_HOME没有得到解决。%ANT_HOME%\bin将 Path 系统环境变量更改为c:\apache-ant\apache-ant-1.8.2\bin.

回答by Joshua

I had a similar issue, but the reason that %ANT_HOME% wasn't resolving is that I had added it as a USER variable, not a SYSTEM one. Sorted now, thanks to this post.

我有一个类似的问题,但 %ANT_HOME% 没有解决的原因是我将它添加为 USER 变量,而不是 SYSTEM 变量。现在排序,感谢这篇文章。

回答by Cugomastik

create a script including the following; (replace the ant and jdk paths with whatever is correct for your machine)

创建一个脚本,包括以下内容;(用适合您机器的任何路径替换 ant 和 jdk 路径)

set  PATH=%BASEPATH%
set ANT_HOME=c:\tools\apache-ant-1.9-bin
set JAVA_HOME=c:\tools\jdk7x64
set PATH=%ANT_HOME%\bin;%JAVA_HOME%\bin;%PATH%

run it in shell.

在 shell 中运行它。

回答by Desmond

When Environment variables are changed log off and log in again so that it will be applied.

更改环境变量后,请注销并重新登录以应用它。

回答by wordsforthewise

I downloaded ant (http://ant.apache.org/bindownload.cgi), unzipped to my C drive, and used the windows 'doskey' command:

我下载了 ant ( http://ant.apache.org/bindownload.cgi),解压到我的 C 盘,并使用 windows 'doskey' 命令:

doskey ant=C:\apache-ant-1.9.6\bin\ant.bat $*

this will work as long as you use the same command console, to make it permanent is more difficult: http://darkforge.blogspot.com/2010/08/permanent-windows-command-line-aliases.html

只要您使用相同的命令控制台,这将起作用,使其永久更难:http: //darkforge.blogspot.com/2010/08/permanent-windows-command-line-aliases.html

回答by SteadyBigman

Had the same problem. The solution is to add a \at the end of %ANT_HOME%\binso it became %ANT_HOME%\bin\

有同样的问题。解决办法是\在末尾加一个,%ANT_HOME%\bin这样就变成了%ANT_HOME%\bin\

Worked for me. (Should be system var)

对我来说有效。(应该是系统变量)

回答by User6

Please follow these steps

请按照以下步骤操作

  1. In User Variables

    Set VARIABLE NAME=ANT_HOME VARIABLE PATH=C:\Program Files\apache-ant-1.9.7

  1. 在用户变量中

    设置变量名称=ANT_HOME 变量路径=C:\Program Files\apache-ant-1.9.7

2.Edit User VariablePATH = %ANT_HOME%\bin

2.编辑用户变量PATH = %ANT_HOME%\bin

  1. Go to System Variables

    • Set Path=%ANT_HOME%\bin
  1. 转到系统变量

    • 设置路径=%ANT_HOME%\bin

回答by britt

even with the environment variables set, I found that ant -versiondoes not work in scripts. Try call ant -version

即使设置了环境变量,我发现它ant -version在脚本中不起作用。尝试call ant -version

回答by Ravi Shankar Kota

Need to see whether you got ant folder moved by mistake or unknowingly. It is set in environment variables.I resolved this once as mentioned below.

需要查看您是否误操作或无意中移动了 ant 文件夹。它设置在环境变量中。我解决了一次,如下所述。

I removed ant folder by mistake and placed in another folder.I went to command prompt and typed "path". It has given me path as "F:\apache-ant-1.9.4\". So I moved the ant back to F drive and it resolved the issue.

我错误地删除了 ant 文件夹并放在另一个文件夹中。我转到命令提示符并输入“路径”。它给了我路径为“F:\apache-ant-1.9.4\”。所以我将蚂蚁移回 F 驱动器并解决了问题。