It's not a secret anymore!
The moose likes Ant, Maven and Other Build Tools and the fly likes Problem while installing ANT!! Help me here!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Problem while installing ANT!! Help me here!!" Watch "Problem while installing ANT!! Help me here!!" New topic

Problem while installing ANT!! Help me here!!

jyothi sunke
Ranch Hand

Joined: Sep 11, 2002
Posts: 65
Hi all,
I downloaded the version and extracted to c:\apache-ant-1.5.2 folder and set ANT_HOME, JAVA_HOME and Path environment variables.
JDK I am using is, j2sdk1.4.1_01. I am just wanted to run the examples from "Oreilly Ant - The Definitive Guide". I downloaded the examples from oreilly website and tried to run the build scripts,
chapter1 directory has required build.xml file.
I am getting Java Usage option as below..
Usage: java [-options] class [args...]
(to execute a class)
or java -jar [-options] jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp -classpath <directories and zip/jar files separated by ;>
set search path for application classes and resources
set a system property
enable verbose output
-version print product version and exit
-showversion print product version and continue
-? -help print this help message
-X print help on non-standard options
enable assertions
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
What might be the problem/reason?? I am very desperate..

Greg Charles

Joined: Oct 01, 2001
Posts: 2967

When you execute ant on Windows command prompt, you are actually running ant.bat from the ANT_HOME/bin directory. From bash or other Unix-like shell, it is just ant in the same directory. That script sets some things up, but mostly just runs a java program. The main line is something like:
$JAVACMD -classpath "$LOCALCLASSPATH" -Dant.home="${ANT_HOME}" "$ANT_OPTS"
The JAVACMD, LOCALCLASSPATH, and ANT_OPTS are set up by the script (but based on JAVA_HOME and CLASSPATH from your environment.) ANT_HOME is taken from your environment.
I do have a point here. I think it's the execution of ant itself that is failing. Maybe you can doublecheck your variables. Especially on Windows, you have to be sure they are set up before you open the command window. You can check them before you execute ant, by typing:
echo $ANT_HOME
(etc.) If all that looks good, you can put echo statements into the script itself. There's got to be something simple wrong.
jyothi sunke
Ranch Hand

Joined: Sep 11, 2002
Posts: 65
Hi Greg,
Thanks for your response. I also think there might be a simple mistake, but I am not able find that. Looks like everything is right.
When I am trying to run this command from command prompt,
c:\>java -Dant.home=c:\apache-ant-1.5.2
I am getting following error,
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/Main
My OS is Windows 2000. And I set the properties as below,
What should I do here??
Thanks in advance,
Greg Charles

Joined: Oct 01, 2001
Posts: 2967

Well, in the case of running the java command yourself, you have to set your classpath to include at least ant.jar, and preferably all jars, from the ANT_HOME/lib directory. The ant (or ant.bat) should do that for you automatically if the ANT_HOME variable is set.
Given that you're in Windows, I recommend editing ANT_HOME/bin/ant.bat and removing the first line (@echo off). That way you should see what it's doing as it does it. Make a backup of that file before you start editing it, just in case.
narasimharao konjeti
Ranch Hand

Joined: Apr 26, 2003
Posts: 130
ur problem requires these classpath and path setting.
set JAVA_HOME env variable as system environment variable. then set ur ANT_HOME env variable value.
then set path for jdk and ant and say
build. it will build ur required .war or .ear files
nr konjeti

"Unwise to sweat petty stuff, wise to pet sweaty stuff."
narasimharao konjeti
Ranch Hand

Joined: Apr 26, 2003
Posts: 130
and apache home set as
AND SET CLASSPATH IN classpath.bat fine in apache
jyothi sunke
Ranch Hand

Joined: Sep 11, 2002
Posts: 65
Thanks to both of you...By the way my problem solved. I included the ant.jar in my classpath..
now it is working fine..
Thanks a lot,
Al Larson

Joined: May 10, 2003
Posts: 1
Hi All:
I had the same problem, and what was causing it in my case was how I set my ANT_HOME. I had it set to:
I took Greg Charles' advice and took out the @echo off at the start of the ant.bat file. When I looked at the output I saw things like 'E:\>if ""E:\apache-ant-1.5.3-1\\lib\xml-apis.jar"" == """" goto gotAllArgs'.
I took out the last slash and set ANT_HOME to:
and it finally worked. Thanks a lot for the help!
I agree. Here's the link:
subject: Problem while installing ANT!! Help me here!!
It's not a secret anymore!