开发者

specifying classpath for built-in ant tasks

开发者 https://www.devze.com 2022-12-25 03:04 出处:网络
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?

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&g开发者_如何学运维t; while guaranteeing it's using my jsch.jar?


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消