0

I keep getting that error, in Command Prompt, even though I have followed both the online instructions and the Question solution here ant - not recognized as an internal.

I've followed this: ant.apache.org/manual/install.html and have downloaded Apache ANt 1.8.2 and set my variables to C:\ant, which is what I was using for the ant install. ANT_HOME was the variable that I was using. I added this on to the environment var path: %ANT_HOME%\bin;. I even made another variable and called it PATH and added %ANT_HOME%\bin; to it. I did all this in the System variables. After a restart, I logged in and it still did not allow me to use the ant -version command to retrieve any information about the ANT install. I have also started several new Command Prompt instances and I was still getting an error from "ant -version".

My System Variables have both ANT_HOME and JAVA_HOME accounted for. C:\ant is where my ANT_HOME is, so I set the ANT_HOME variable's value to that. %JAVA_HOME%\bin;%ANT_HOME%\bin; is at the end of the 'Path' variable. I resetted my computer and made several Command Prompt instances afterwards, and still doesn't recognize ANT. I can request Java's information without any difficulty, but not ANT's. Please assist.

I've set the variables correctly, and also set another PATH that isn't my original path variable. Please let me know if there is something that I'm doing wrong.

EDIT: updated by request of trashgod.

Apurv
  • 3,615
  • 3
  • 28
  • 49

5 Answers5

1

I found that the user variable if you'd got spaces in the path needed to be

ANT_HOME = "C:\Program Files\Adt\ant"

Note the enclosing quotes. Then %ANT_HOME%\bin in the path meant that ant worked in the command prompt from any location

Steven Penny
  • 82,115
  • 47
  • 308
  • 348
Mike
  • 11
  • 1
1

Just checking:

  • You need to define in your environment variables ANT_HOME=C:\ant as well as the relevant JAVA_HOME set.
  • You need in your PATH %ANT_HOME%\bin as well as %JAVA_HOME%\bin.
  • You need to verify that ant.bat is in %ANT_HOME%\bin.
  • You can remove the @echo off line from ant.bat. It's the first line. This way, when you type ant as a command, it'll show you all the commands being executed.

Check the value of your %PATHEXT% variable. This are the extensions added to commands to locate executable commands.

For example, mine is

.COM;.EXE;.BAT;.CMD;.PL;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1

This means, it first tries ant.com, then ant.exe, and finally ant.bat before it executes ant.bat.

What output are you given? Are you getting ant is not recognized as an internal or external command error?

David W.
  • 98,713
  • 36
  • 205
  • 318
  • Checked everything here. The .PSC1 wasn't in the %PATHEXT% Yes, I still get the Ant is not recognized – Kevin M. Kelly Sep 13 '11 at 03:48
  • Create a command called `foo.bat` and put it in the `C:\Ant\bin` directory. All this command has to do is echo "You've got me!". You simply want to see if you can execute a command located in that directory. The maximum size for PATH is 2048 characters. Could your PATH be too long? Take a close look at it and make sure there's no bad directory formatting in it. I suggest you cut and paste your path in an editor, so you can see it all at once. – David W. Sep 13 '11 at 15:38
  • - When I write "cd C:\ant\bin\" and then execute foo.bat, it executes. – Kevin M. Kelly Sep 14 '11 at 21:28
  • JAVA_HOME does execute, though. Anything else? – Kevin M. Kelly Sep 14 '11 at 23:19
  • Have you tried removing the `@echo off` at the beginning of the `ant.bat` file? This will help show you what lines in the file are executing (if any). Have you also tried typing `C:\ant\bin\ant.bat` to see if it executes? Maybe there's another ant.bat in the path? – David W. Sep 15 '11 at 01:49
  • Took that off. What should I be looking for after I did the C:\ant\bin\ant.bat? this does execute, though. How do I find out about ant.bat having a duplicate? – Kevin M. Kelly Sep 15 '11 at 02:52
  • If you removed the `@echo off`, you should see the output of the ant.bat as it is executing. If you don't see anything, then the script isn't executing. It's very likely that there's another `ant` command in your Path. Echo our your `%PATH%` variable and see if you have another `ant` program in your path. If you have Perl installed on your system, you can use my [which.pl](http://dl.dropbox.com/u/433257/which.pl) script to do that for you. – David W. Sep 15 '11 at 15:01
  • I can't see it here in the path. No duplicates. Would I be able to cut and paste the path here? I do not have PERL installed. – Kevin M. Kelly Sep 16 '11 at 18:33
  • As in I do not see another Apache instance in plain sight in my PATH. Is there a program that it could be in the path that is called something else? – Kevin M. Kelly Sep 19 '11 at 18:07
  • For some odd strange reason, your `ant.bat` file isn't executing when requested. Yet, other bat files in the same directory are. Can you execute `C:\ant\ant.bat` (that is, give the ant.bat the FULL path)? – David W. Sep 19 '11 at 18:44
  • If you mean: C:\ant\bin\ant.bat, it does execute in C PROMPT, – Kevin M. Kelly Sep 19 '11 at 19:23
  • You can execute Ant with the full path and you can execute other batch scripts. There must be another ant command in your path. Look at [this](http://stackoverflow.com/questions/304319/is-there-an-equivalent-of-which-on-windows). This points to an equivalent of the which command I posted earlier, but this is in batch itself. – David W. Sep 20 '11 at 00:20
  • Dave: where do I put whereis to execute it? – Kevin M. Kelly Sep 20 '11 at 23:47
  • @kevinkvs: Put it somewhere in your PATH. I usually just these things into `C:\Windows` although that's probably a bad idea for some reason. – David W. Sep 21 '11 at 21:05
  • You have an _ant.exe_ in your `PATH`? That's a problem because when you type in `ant`, you are executing that one. You can specify `ant.bat` which will guarantee your hitting the correct one, or use the full path name (`C:\Ant\bin\ant.bat`), or rename that `ant.exe` to `antprog.exe` (or delete it entirely). Then, your ant.bat will execute. – David W. Sep 25 '11 at 02:38
0

Not sure if you solved this problem yet but from my experience, you need to replace the %ANT_HOME%with the actual path C:\ant. I also replace my JAVA_HOME with the actual path C:\Java\jdk\. Only then my Ant and Java commands start working properly. Hope this help you.

Iso
  • 3,228
  • 2
  • 18
  • 18
0

just so that this question can be answered - based on our discussions I think the ANT_HOME variable should be set to c:\ant and not c:\ant\bin in order for it to work

Ross
  • 2,918
  • 1
  • 20
  • 27
  • I have set the ANT_HOME environment variable to C:\ant and verified that C:\ant was shown in the echo %ANT_HOME% call. I am still getting an error with ant -version, though. – Kevin M. Kelly Sep 12 '11 at 13:35
  • and when you echo your path does it show %ANT_HOME% or the actual path :C:\ant. If it is resolving the variable correctly it should show the actual path – Ross Sep 12 '11 at 13:44
  • is it only printing c:\ant? I presume in your path you have it set up so that path contains: %ANT_HOME%\bin and when you echo your path variable you get: c:\ant\bin – Ross Sep 12 '11 at 14:16
  • No, %ANT_HOME% now prints out "C:\ant" now. – Kevin M. Kelly Sep 12 '11 at 14:56
0

After an hour or so of frustration, I found that I had made a very simple mistake:

In instances such as this one, where you add to your PATH variable, make sure you do not introduce any spaces. When I added %ANT_HOME%\bin to my PATH variable, I mistakenly added a space after the previous semicolon. This will cause anything after the space to be ignored.

Matt Fenwick
  • 44,546
  • 19
  • 115
  • 184
ggrigery
  • 401
  • 3
  • 13