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>
Related
I'm using Ant to deploy my application to the production application server(WebSphere).
I use the sample configuration file located in the ${WORKLIGHT_INSTALL_DIR}\configuration-samples folder. the configuration file is marked as suitable for Websphere liberty and Apache derby.
On the configuration sections i change the value (and only this value according with the documentation IBM) of the path element tag (below the code reported).
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<pathelement location="C:\workspace\jQueryMobileApplication\bin\jQueryMobileApplication.war"/>
</classpath>
Setting as location my application war's path. The build.xml file is located in the same folder of my project's war file.
When i type the command :
ant -f <filename>.xml
i get this exception:
Buildfile: C:\IBM\WorklightSRV\WorklightServer\configure-liberty-derby.xml
[taskdef] Could not load definitions from resource com/worklight/ant/defaults.properties. It could not be found.
I'm a newbie with Worklight development(and also with Ant Deployment), so i appreciate any help even if this may be a trivial question.
The classpath is for the worklight-ant.jar to define the tasks to ant
ex.
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<pathelement location="./lib/worklight-ant.jar" />
</classpath>
</taskdef>
After the ant tasks are loaded you can use one of the worklight ant tasks to do your commands
ex.
<echo>Export war file</echo>
<war-builder projectfolder="./<ProjectDirectory>" destinationfolder="bin/war" warfile="bin/Application.war.${env}" classesFolder="<ProjectDirectory>/bin/classes" />
From what i know this will create the war for you but you will have to deploy it manually.
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"/>
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.
I am executing lot of scp and sshexec and other remote commands from an ant build script. These commands don't work if jsch.jar isn't in the ant lib directory. To make it work, I copied the JAR into the ant lib directory, but this is not a good solution, as anyone else wanting to run the script would have to do the same thing. To run the ant target from Teamcity, we will have to explicitly set the path of the lib file.
Is there a way I can specify the path of the JAR in the ant build XML itself?
Thanks all for your answers. I am managed to get it work with classloader task. This is what I did.
<project basedir="." >
<property environment="env"/>
<taskdef resource="net/jtools/classloadertask/antlib.xml">
<classpath>
<fileset dir="${basedir}/lib" includes="ant-classloader*.jar"/>
</classpath>
</taskdef>
<!--Add JSCH jar to the classpath-->
<classloader loader="system">
<classpath>
<fileset dir="${basedir}/lib" includes="jsch*.jar"/>
</classpath>
</classloader>
<target name="Test">
<scp todir="user1:pass1#server1:/tmp" trust="true" >
<fileset dir="dir1">
<include name="test.txt" />
</fileset>
</scp>
</target>
</project>
As you can see here, I didn't have to give any dependant target for my "Test" target, it just works. It uses classloader, which appends jsch.jar to the system classloader.
One possible work around would be to use the -lib command line option to tell ant where to look for additional jars. Perhaps you could create a wrapper script that calls ant with this option set.
Another way would be to move the ant-jsch.jar file (this is the jar that comes with ant that defines the tasks, not the jsch.jar file you need to download separately) out of your ant lib directory, and create a taskdef for your ssh task separate to the built in one, then set the classpath for this task to the jsch.jar and the ant-jsch.jar:
<taskdef name="sshexec"
classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec">
<classpath>
<pathelement location="jsch-0.1.44.jar"/>
<pathelement location="ant-jsch.jar" />
</classpath>
</taskdef>
I'm not sure this will help you though, since it also involves making changes to the lib directory.
As far as I'm aware, it's not currently possible to specify the extra jars required for the built in tasks in the build file itself in general. There are some special cases, like junit for instance.
To ensure your build is more cross platform I'd suggest using dependency management. The ivy plug-in can automatically install the version of your build's plugin at build-time.
This approach means the last jar you'll ever need to install into your ANT lib is ivy-2.2.0.jar :-)
First declare your project's dependencies in the file ivy.xml
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="anttask" description="Jars implementing ANT tasks"/>
</configurations>
<dependencies>
<dependency org="com.jcraft" name="jsch" rev="0.1.42" conf="anttask->default"/>
</dependencies>
</ivy-module>
Within your build.xml run ivy and use it to populate a custom classpath based on the ivy configuration:
<target name='init' description='Resolve project dependencies and set classpaths'>
<ivy:resolve/>
<ivy:cachepath pathid="anttask.path" conf="anttask"/>
</target>
Finally, elsewhere in your build declare your ANT tasks using the class path now automatically populated by ivy.
<target name='dosomething' depends="init">
<taskdef name="sshexec"
classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"
classpathref="anttask.path"/>
..
..
</target>
This approach works for all ANT plug-ins, most of which are available in the central Maven repository. The second benefit is that it's easy to upgrade the plug-in versions across all builds.