如何以无配置方式将可选任务 sshexec 加载到 Ant 中? [英] How do I load optional task sshexec into Ant in a no-configuration manner?

查看:25
本文介绍了如何以无配置方式将可选任务 sshexec 加载到 Ant 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sshexec,它依赖于 jsch-0.1.48.jar.我不能把它放在 ant/lib 目录中,因为其他希望使用相同构建脚本的用户必须先在他们的机器上进行配置才能这样做.

I am using sshexec, which depends on jsch-0.1.48.jar. I can't just put that into the ant/lib directory because other users wishing to use the same build script will have to make a configuration on their machine before they can do so.

我想要做的是能够引用 jsch-0.1.48.jar 作为项目的一部分.目前,我将它放在 project/libs 目录中,我正在尝试以下操作:

What I want to do is to be able to reference jsch-0.1.48.jar as part of the project. Currently, I have it sitting in project/libs directory and I am trying something like:

<property name="lib" location="lib"/>

<taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec">
  <classpath>
    <pathelement location="${lib}/jsch-0.1.48.jar"/>  
  </classpath>
</taskdef> 

<target name="sshcmd" description="ssh command">    
    <sshexec host="X.X.X.X" username="USER" password="PASS" command="cmd" trust="true"/>
</target>

但这不起作用:

C:\dev\trunk\project:>ant sshcmd
Buildfile: C:\dev\trunk\project\build.xml

BUILD FAILED
C:\dev\trunk\project\build.xml:275: taskdef A class needed by class org.apache.tools.ant.taskdefs.optional.ssh.SSHExec cannot be found: com/jcraft/jsch/Logger
using the classloader AntClassLoader[C:\dev\trunk\project\lib\jsch-0.1.48.jar]

Total time: 0 seconds

推荐答案

jsch jar 与我的项目一起打包.因此,我没有下载它,而是将其复制到 ant 库中.构建将在第一次运行时失败,这对我的目的来说很好.它将第二次成功,因为 jar 将在库中并会在启动时加载.

The jsch jar is packaged with my project. So instead of downloading it, I am copying it into the ant library. The build will fail the first time it is run, which is fine for my purposes. It will succeed the second time because the jar will be in the library and would be loaded at start.

<target name="jschset" description="Set the jar">   
    <copy file="${lib}/jsch-0.1.48.jar" tofile="${ant.home}/lib/jsch-0.1.48.jar"/>
</target>

这篇关于如何以无配置方式将可选任务 sshexec 加载到 Ant 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆