views:

30

answers:

2

Recently I have been trying to make changes so I can do builds through Ant and the command line. This has forced me to reconfigure my setup. In order to make java available on the class path I typed the following in the command propmt...

set JAVA_HOME=C:\Java\JDK 1.6.0_08

that being the directory of my java installation. Then I will set my ANT_HOME variable to the following

set ANT_HOME=C:\Ant

I can check both of these following doing this by doing

javac

and

ant

on the command line and getting the usual output signifying that they are being read.Following this I will set them both on the

path
by doing the following

set PATH=%PATH%;%JAVA_HOME%\bin;%ANT_HOME%\bin

After doing this I check the command line for each of them and they will work fine.

The problem that I am having is that randomly, I will go back and do the same command, and it will tell me that

"ant" is not recognized as an internal or external command...

I know this is the message you get when you type an incorrect command. Why is is that every website, tutorial and book I look at for configuring these services tells me to do the same process and none of them are working? Am I completely missing something?

+2  A: 

If you're on Windows remember that any changes that are made in a command window only endure until the window is closed.

Go to My Computer --> Properties --> Advanced --> Environment Variables and configure your variables here instead.

After that, close your command line window and open it again... Windows should now be able to recognize your commands.

Regards.

StudiousJoseph
Thank you, but the problem is not that it wont recognize the commands initially, it is that after it has recognized them, I will go back at an arbitrary time, and it wont recognize one of them anymore.
CitadelCSAlum
@CitadelCSAlum ...and setting them in My Computer / Properties etc. instead of using `set` on the command line solves that problem. Did you try it out?
Jesper
That is the correct way of doing it. Yes
StudiousJoseph
+2  A: 

Setting environment variables in a console will only set them for the current process. So when you close the console, or run a different console, you will lose your changes.

Make sure you aren't doing that, and make sure something else you are running isn't changing the system path.

I would suggest creating a start-up script for your build that contains the environment settings. I create one named "ant.bat" at the root of my build tree. This way it doesn't matter if the environment is set, you can always find a bat file in the current directory. It will take care of setting the environment and calling ant.

Something like this:

set JAVA_HOME=C:\Java\JDK 1.6.0_08
set ANT_HOME=C:\Ant

set PATH=%PATH%;%JAVA_HOME%\bin;%ANT_HOME%\bin

call %ANT_HOME%\bin\ant %1 %2 %3 %4 %5 %6 %7 %8 %9

This also has the advantage of documenting the environment needed for the build.

JasonMArcher