5

I have installed Apache Ant and set the correctly the Path, CLASS_PATH and ANT_PATH variables. When I run a jar task in a command line within my project folder where the build.xml file is, I get the following error:

BUILD FAILED

C:\Documents and Settings\TonyS\My Documents\My Workspace\code\build.xml: 32:

The following error occurred while executing this line:
jar:file:/C:/Documents%20and%20Settings/TonyS/My%20Documents/Ant/apache-ant-1.8.1/lib/ant.jar!org/apache/tools/ant/antlib.xml:37: Could not create task or type: componentdef.

Ant could not find the task or a class this task relies upon.
karel
  • 5,489
  • 46
  • 45
  • 50
Anto
  • 4,265
  • 14
  • 63
  • 113
  • Componentdef.class and Jar.class are found in ant.jar itself. Is your ant.jar corrupt - is it 1.4 Mb or so in size? – JoseK Oct 12 '10 at 08:14
  • I assume you're talking about the `PATH` (not `Path`), `CLASSPATH` (not `CLASS_PATH`) and `ANT_HOME` (not `ANT_PATH`) *environment variables*? – zb226 Apr 11 '17 at 11:52
  • I don't remember, that was almost 7 years ago.. – Anto Apr 11 '17 at 12:43

4 Answers4

5

I had this error and found it was caused by having an older version of ant.jar in the classpath.

Peter Jamieson
  • 745
  • 5
  • 10
4

One possibility is you may have another version of ant installed on your system and your PATH pointing to it.

Check what is ANT_HOME set to.

Run ant -version and see if it shows up 1.8.1

Raghuram
  • 51,854
  • 11
  • 110
  • 122
1

Add the following config in ~/.bashrc

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

Don't forget source ~/.bashrc

Hope useful for you!

Ma Jane
  • 11
  • 2
1

you have duplicate ant in your environment.

My case was: I am using 1.9.7 ant, but ant -version gave me 1.7.1 I installed weblogic and it has 1.7.1 ant, after rename MW_HOME, the issue was gone.

I found this while I was using 1.7.1 to test junit. it shows a warning.

junit:
    [junit] WARNING: multiple versions of ant detected in path for junit
    [junit]          jar:file:/D:/wls12120/oracle_common/modules/org.apache.ant_1.7.1/lib/ant.jar!/org/apache/tools/ant/
Project.class
    [junit]      and jar:file:/D:/apache-ant-1.7.1/lib/ant.jar!/org/apache/tools/ant/Project.class
    [junit] Running HelloWorldTest
Neal.Shan
  • 128
  • 1
  • 11