Yuvi Masory
Yuvi Masory

Reputation: 2674

specifying classpath for built-in ant tasks

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?

Upvotes: 4

Views: 3296

Answers (3)

Thierry Gu&#233;rin
Thierry Gu&#233;rin

Reputation: 11

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

Upvotes: 1

Slava Imeshev
Slava Imeshev

Reputation: 1390

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 .../>

Upvotes: 1

VonC
VonC

Reputation: 1324278

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.

Upvotes: 1

Related Questions