I've created a custom ant task according to Apache doc.
Running ant, I get:
BUILD FAILED
/home/russ/blackpearl/fun/build.xml:92: taskdef class com.etretatlogiciels.ant.task.SqlScriptPreprocessor cannot be found using the classloader AntClassLoader[]
I have the following in build.xml prior to my use of
<taskdef name="sqlscriptpreprocessor" classname="com.etretatlogiciels.ant.task.SqlScriptPreprocessor" />
...and I've dropped a copy of sqlscriptpreprocessor.jar into my local lib subdirectory (should be on classpath) and even into /usr/bin/ant/lib (which is apache-ant-1.8.2).
Where should this go? Or what other problems are anticipated that I should look for?
Thanks very much for any and all comments.
Russ
Try nesting
<classpath>
<pathelement location="C:\**\**.jar"/>
</classpath>
Inside the taskdef, e.g.
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="C:\myfolder\ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
Ideally it should pick up from ant/lib, but specifying pathelement forces it to look in the given path.
Related
I got an error when runnning target replace to xmltask:
C:\Tools\build.xml:432: The following error occurred while executing this line:
C:\Tools\build.xml:408: Failed to specify text in replace
the problem is that my coworker had no issues running the same code on his computer. I can't figure out why I got the error while my coworker didn't.
the part of build.xml is as follow:
<target name="replace" depends="init" description="replace node.">
<xmltask source="${my-file}" dest="${my-file}">
<replace path=
"/*[local-name()='server']
/*[local-name()='profile']
/*[local-name() = 'subsystem'][1]"
withFile="${devlogfile}"/>
</xmltask>
</target>
<target name="init">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${ant.lib.dir}/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath>
<pathelement path="${ant.lib.dir}/xmltask.jar"/>
</classpath>
</taskdef>
</target>
the part of property file is as follow:
my-file=c:/old.xml
devlogfile=c:/new.xml
[Converted from the comments section]
Did you compare the jdk and classpath in the case of your co-worker and yourself ? It's impossible to tell with the information given so far, but it's possible you are using different parsers.
The error message suggests Ant doesn't find the devlogfile file itself.
Are you sure the properties file is passed properly to your ant runtime ? How are you passing it ?
I'm using ant-contrib in my build script
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="ant/ant-contrib-0.6.jar"/>
</classpath>
</taskdef>
It works. But when I'm calling some target in this script from another ant file using ant task, I'm getting the error.
<ant antfile="build.xml" target="make" dir="${client.project.location}/ant"/>
Please, help me to fix the problem. Thanks
In your code we can see
<classpath>
<pathelement location="ant/ant-contrib-0.6.jar"/>
</classpath>
You need to give path location="/home/[some
path]/ant-contrib-0.6.jar"
you can do one more thing,you need to copy your ant-contrib-0.6.jar
into ANT_HOME/lib folder and remove your tag completely from you code.
Note: Second option is always better.
I had to set usenativebasedir="true" when calling ant task
I am getting following while doing ant build:
Build\build.xml:247: Problem: failed to create task or type
for
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.
build.xml line 247 is <for param="file">
Already defined <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>, it didn't work. Then I specifically added following but it is still not working.
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${env.ANT_HOME}/lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
I have ant-contrib-1.0b3.jar at C:\Softwares\apache-ant-1.8.4\lib directory. What is missing here?
If you placed the AntContrib jar in $ANT_HOME/lib directory, all you really need to do is this:
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
Actually to use the <for/> task, you need to do this:
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
Note you have to use antlib.xml and not antcontrib.properties. Read the Installation directions very carefully. It's easy to miss.
If you are doing this in a group project, I recommend that you put your ant-contrib.jar in your project. THen add them to your project in your version control system. That way, other developers can use your build with the ant-contrib tasks without downloading the ant-contrib jar and installing it in their $ANT_HOME directory themselves.
Let's say you create a directory called ant-contrib.dir and put that in the root of your project, then put the ant-contrib jar in that folder. Just put this in your project:
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<fileset dir="${basedir}/ant-contrib.dir"/>
</classpath>
</taskdef>
Ant needs to be aware of the the dependency. The following is a more succinct version of David W's answer. Add the equivalent of the following to your ant project:
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="relative/path/to/ant-contrib-1.0b3.jar"/>
<taskdef resource="net/sf/antcontrib/antlib.xml" classpath="relative/path/to/ant-contrib-1.0b3.jar"/>
On my machine, I have a plugin for Ant. It's called ant-contrib. It was easy to install. I just put the ant-contrib-0.3.jar in the lib folder of Ant. It lets me do some cool things with Ant, including if statements. Now, I want to run my build scripts using Bamboo. Currently the version of Ant that bamboo uses does not have these capabilities so my scripts fail. How do I install plugins like ant-contrib in bamboo?
My recommendation is to commit the ant-contrib jar alongside your source code and make your build more portable by declaring the tasks as follows:
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${lib.dir}/ant-contrib-0.3.jar"/>
</classpath>
</taskdef>
Another alternative is to use ivy to manage your build's 3rd party dependencies.
Copy ant-contrib-version.jar to the lib directory of your Ant installation, or on your CLASSPATH environment variable. If you want to use one of the tasks in your project.
For Ant verssion 1.6 and above, add the lines below in your build.xml file
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="/home/svnadmin/apache-ant-1.8.4/lib/ant-contrib-version.jar"/>
</classpath>
</taskdef>
For Ant Version 1.5, add the below lines in your build.xml file. Also, you must use the the .properties file instead of antlib.xml
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="/home/svnadmin/apache-ant-1.5.0/lib/ant-contrib-version.jar"/>
</classpath>
</taskdef>
I have a jar with the following structure
com
merc
test.class
lib
xyz.jar
applicationContext.xml
test.class uses xyz.jar. Using ant java task, how do i include the lib folder in the classpath, so that I can execute test.class
Thanks
Did you try as documented here (like the snippet below) and if so, did you get any error?
<java classname="com.merc.test">
<classpath>
<pathelement location="lib/xyz.jar"/>
</classpath>
</java>