This is what my build.xml file looks like:
<project name="test" xmlns:cpptasks="antlib:net.sf.antcontrib.cpptasks">
<target name="build-native">
<mkdir dir="/home/varun/Desktop/lucene/3018-test/check"/>
<cpptasks:cc outtype="executable" subsystem="console" outfile="BuildNativeDir" objdir="/home/varun/Desktop/lucene/3018-test">
<fileset file="/home/varun/Desktop/lucene/3018-test/hello.c" />
</cpptasks:cc>
</target>
</project>
When I run the command ant build-native I get an error:
BUILD FAILED
/home/varun/Desktop/lucene/3018-test/build.xml:4: Problem: failed to create task or type antlib:net.sf.antcontrib.cpptasks:cc
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-/usr/share/ant/lib
-/home/varun/.ant/lib
-a directory added on the command line with the -lib argument
Total time: 0 seconds
But my CLASSPATH is set to /usr/share/ant/lib and I have placed the ant-contrib-1.0b3.jar in /usr/share/ant/lib/ant-contrib-1.0b3.jar.
What am I doing wrong?
cpptask is not included in ant-contrib-*.jar. You have to download that separately.
I just tried cpptasks-1.0-beta5 but it did not compile. cpptasks-1.0-beta4 had a precompiled jar in the archive and that worked fine.
Related
BUILD FAILED
E:\Tasks\Task - 2 (ant dd)\Testing\build.xml:50: The following error occurred while executing this line:
E:\Tasks\Task - 2 (ant dd)\Testing\checks.xml:123: The following error occurred while executing this line:
E:\Tasks\Task - 2 (ant dd)\Testing\accountsurlcheck.xml:21: The following error occurred while executing this line:
E:\Tasks\Task - 2 (ant dd)\Testing\accountsurlcheck.xml:54: Problem: failed to create task or type stopwatch
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
Im getting this eror when I run ant .
I have copied ant-contrib-0.5.jar to the lib of ant installed directory and also added <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> to my build.xml.
line 54 of accountsurlcheck.xml :
<stopwatch name="total_time" action="start"/>
Line 21 :
<antcall target="urllist"/>
Your taskdef for ant-contrib is missing a classpath that points to the ant-contrib jar.
<taskdef
classpath="/path/to/ant-contrib.jar"
resource="net/sf/antcontrib/antcontrib.properties"
/>
I have the following build.xml solely to demonstrate the problem:
<project
xmlns:ivy="antlib:org.apache.ivy.ant"
name="test" default="test-ivy">
<target name="test-ivy">
<ivy:settings />
</target>
</project>
When invoking it with Ant (1.7.1) I get:
$ ant
Buildfile: build.xml
test-ivy:
BUILD FAILED
/home/voops/test/build.xml:7: Problem: failed to create task or type antlib:org.apache.ivy.ant:settings
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-/usr/share/ant/lib
-/home/voops/.ant/lib
-a directory added on the command line with the -lib argument
Total time: 0 seconds
However the Ivy jar does live in my ~/.ant/lib directory:
$ whoami
voops
$ls /home/voops/.ant/lib/ivy-2.3.0.jar
-rw-rw-r-- 1 voops voops 1222059 Nov 11 14:55 /home/voops/.ant/lib/ivy-2.3.0.jar
It appears that I have to manually indicate where the Ivy jar is located by adding the following element:
<taskdef uri="antlib:org.apache.ivy.ant" resource="org/apache/ivy/ant/antlib.xml" classpath="${user.home}/.ant/lib/ivy-2.3.0.jar"/>
... in my build.xml file. Once this element is added, the build succeeds.
Why is Ant not able to find Ivy even though the Ivy jar is located in the default ~/.ant/lib location and has to be explicitly told to look for it in the said location?
Update: It seems that the above element is only necessary for Ant 1.7.1. For Ant 1.8.2 or Ant 1.9.4, I don't have to add it.
It's due to the XML namespace declaration in the buildfile:
xmlns:ivy="antlib:org.apache.ivy.ant"
Since the prefix ivy: is being used, the uri attribute is needed in the taskdef task to allow calling the task with the prefix:
An example is shown in the typedef documentation:
uri: The uri that this definition should live in. since Ant 1.6
EDIT:
The antlib indicates that Ant by default can load the correct resource if the antlib is placed in the home directory of Ant:
When Ant encounters a element with a namespace URI with this pattern, it will check to see if there is a resource of the name antlib.xml in the package directory in the default classpath.
I would like to use 'ant-contrib', but I could not use it. I tried to use 3 way, without success.
Apache Ant(TM) version 1.8.2
echo $ANT_HOME
/usr/share/ant
./usr/share/ant/lib/ant-contrib-1.0b2.jar
./usr/share/java/ant/ant-contrib-1.0b2.jar
./usr/share/java/ant.jar
*1.*
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
RESULT:
Buildfile: /home/username/build.xml
[taskdef] Could not load definitions from resource net/sf/antcontrib
/antcontrib.properties. It could not be found.
*2.*
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
RESULT:
Buildfile: /home/username/build.xml
[taskdef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
*3.* build.xml in my home, and ant-contrib in home/lib
<classpath id="contrib.classpath.ref">
<fileset dir="${basedir}/lib"/>
</classpath>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="contrib.classpath.ref"/>
RESULT:
Buildfile: /home/username/build.xml:2: Problem: failed to create task or type classpath
Cause: The name is undefined.
Action: Check the spelling.
I dont know other solution where I can iterate through a fileset/custom list doing something on them one by one. Thats why its important me.
Honestly, why there is no clear documentation ?
The problem was that YAN mentioned above. I have more ant in my system.
All in all, I removed them, a tried again my build xml with a brand new downloaded ant.
What is not on the PATH, and started from directory where it is.
I know this is not the best settings, but I could try it what I want, and solving the right setting is just question of time.
Thanks guys above your time and effort.
i got this error while build application jar with ant
Problem: failed to create task or type bind
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
and this a snippet is my build.xml file:
Your <bind verbose="true" load="true" binding="mdb-src/com/arj/sms/xmlHandler/mapping/binding.xml">
requires task definition of JiBX binding compiler. Just like any other custom Ant task. To make it more clear bind is not a "ant tag" like you call it and isn't "part" of ant syntax. You need to define it:
<taskdef name="bind" .. + classname/classpaths/filesets etc..
You have it?
If you have it, then make sure that task definition has proper path to the lib directory of your JiBX installation. Also note that some versions of Ant may not work properly if the JiBX installation path contains a space character.
Good luck.
I've got a build that's a mess. In the end, targets are executed up to 15 times. Most targets are executed over a dozen times. This is because the build and targets are divided into 10 separate build files (build.xml, build-base.xml, compile.xml, etc.).
In many build files, you have at the beginning <property> tasks outside of all targets in the build file. These are usually executed first before any targets are called.
Here is my build.xml file:
<import file="build-base.xml"/>
[...]
<target name="compile-base">
<antcall target="setup-tmpj"/>
<ant antfile="compile.xml" target="compile-base"/>
[...]
</target>
Here's the compile.xml file:
<import file="build-base.xml"/>
<property name="target" value="1.5"/>
<available file="target/gensrc/com" property=gensrc.exists"/>
[...]
<target name="buildAndCompileCodeGen" unless=gensrc.exists">
<blah blah blah/>
</target>
<target name="compile-base" depends="buildAndCompileCodeGen">
<blah blah blah/>
</target>
I execute this:
$ ant -f build.xml compile-base
This calls the target compile-base in the compile.xml file. This is dependent upon the target buildAndCompileCodeGen in the compile.xml file. However, the target buildAndCompileCodeGen is only executed if the property gensrc.exists is unset.
In the compile.xml file is an <available> task that will set the gensrc.exists property, but this task is located outside of all targets in compile.xml. Is that <available> task ever called, so that gensrc.exist is set?
Okay I figured out what's going on...
Yes, when I call the compile-base target in the compile.xml file via the <ant> task, all tasks not under a target are executed before the target I call is executed. That means, if the code is already there, the buildAndCompileCodeGen target is called but not executed.
What I did was combine all the build files into one big file and got rid of all of the <ant> and <antcall> tasks. I had put the <available> task in the combined build.xml file.
In the original circumstance, I would first do a clean, then call compile-base in the compile.xml file. At that time, the <available> task would run. Since I did a clean, the file didn't exist, the property gencode.exists isn't set, and buildAndCompileCodeGen target would run.
When I combined everything, the <available> task would run, set the gencode.exists property. Then, when I did a clean, I would delete the generate code. However, the buildAndCompileCodeGen target still wouldn't execute because gencode.exists has already been set.
What should be done is this:
<target name="compile-base"
depends="buildAndCompileCodeGen">
<echo>Executing compile-base</echo>
</target>
<target name="buildAndCompileCodeGen"
depends="test.if.gencode.exists"
unless="gencode.exists">
<echo>Executiing buildAndCompileCodeGen</echo>
</target>
<target name="test.if.gencode.exists">
<available file="${basedir}/target/gensrc/com"
property="gencode.exists"/>
</target>
In this case, I call compile-base. That will call buildAndCompileCodeGen. That will first call test.if.gencode.exists first. This will be done even if the property gencode.exists already is set. Dependent clauses are run on targets before Ant looks at the if or unless parameters. This way, I don't set gencode.exists until I am ready to execute the buildAndCompileCodeGen target. Now, the available task will be run after I do a clean.