tags:

views:

153

answers:

3

I use the classpath attribute in custom Ant tasks to tell Ant where to find the external task jar, but how do I do the same for built-in tasks?

In my case I'd like to make sure ant uses my copy of jsch.jar for the scp task, and not one that my already be installed on the system. Is there any way I can <scp> while guaranteeing it's using my jsch.jar?

+1  A: 

If your ant call uses $ANT_HOME, you could use just for that ant call a special ANT_HOME value to a custom ant installation, where you make sure your $ANT_HOME/lib contains the right copy of ant-jsch.jar.
See this SO question for more.

VonC
+1  A: 

I think the best way to do it is to define your own task instead of messing with predefined tasks.

<taskdef name="myscp" class="..." classpath="jsch.jar"/>

<myscp .../>
Slava Imeshev
thanks for the idea. i guess i'm not sure what would go in the body of the `<myscp>` task.
Yuvi Masory
Let's step back for a second. You have mentioned that jsch.jar is already installed on the system. How is it installed?
Slava Imeshev
I want to put jsch.jar in my project (meaning some arbitrary relative URL to the build.xml) as opposed to putting it in /usr/share/ant/lib or the ant path in my home directory.
Yuvi Masory
You can add the following line to the local .bashrc export CLASSPATH=$CLASSPATH:/path/to/jsch.jarThen every time time you log in it will be in the classpath.Will this work?
Slava Imeshev
Yes it will but it requires every user to do this. I was hoping to put it in the script so anyone checking out the project can run this ant task without further setup. Not all ant installations have jsch.jar (e.g., Ubuntu's default ant package), so i wanted to provide it and mandate its use in the script. Oh well. :(Thanks again.
Yuvi Masory
A: 

I had the exact same problem and here's what I did: use Google's Jar Jar to change the package names. Here's the build.xml i used:

<project name="Admin WAS Jython" default="jar">
<target name="jar" >
    <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask"
        classpath="jarjar-1.0.jar"/>
    <jarjar jarfile="dist/ant-jsch-copy.jar">
        <zipfileset src="ant-jsch.jar"/>
        <rule pattern="org.apache.tools.ant.taskdefs.optional.ssh.**" result="org.apache.tools.ant.taskdefs.optional.ssh.copy.@1"/>
    </jarjar>
</target>

Then in your ant project use the following:

<taskdef name="scp2"
classname="org.apache.tools.ant.taskdefs.optional.ssh.copy.Scp"
classpath="ant-jsch-copy.jar;jsch-0.1.43.jar"/>

and use the scp2 task instead of scp

Thierry Guérin