本文介绍了有没有办法从 build.xml 中指定本地 jsch.jar 的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

build.xml 包含 任务,所以我提供了 jsch.jar 和与 build.xml 位于同一目录中的其他库.

build.xml contains <scp> and <sshexec> tasks, so I provide jsch.jar andother libraries in the same directory together with build.xml.

以下任务定义:

<taskdef name="scp"
    classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp"
    classpath="WebContent/WEB-INF/lib/jsch-0.1.43.jar" />

抛出错误

A class needed by class org.apache.tools.ant.taskdefs.optional.ssh.Scp
cannot be found: com/jcraft/jsch/UserInfo

我无法修改标准的 Ant 安装(例如将 jsch.jar 放入 ant lib目录,或删除 ant-jsch.jar),或添加命令行标志,或修改系统环境变量等:脚本必须使用默认 Ant 运行在不同的系统上.

I cannot modify the standard Ant installation (e.g. put jsch.jar in ant libdirectory, or remove ant-jsch.jar), or add command-line flags, or modifysystem environment variables, etc.: the script has to run with default Anton different systems.

我实际上是在重新发布最初在这里提出的问题:http://ant.1045680.n5.nabble.com/specifying-location-of-an-external-library-within-build-xml-td1344969.html

I'm actually reposting the question originally asked here:http://ant.1045680.n5.nabble.com/specifying-location-of-an-external-library-within-build-xml-td1344969.html

但无法得到有关类加载器工作的答案.

but could not get the answer about classloader to work.

推荐答案

最后我找到了一个可行的解决方案(至少对于 Ant 1.7.1).首先,您必须从 ANT_HOME/lib 中删除 ant-jsch.jar,因为 Ant 抱怨它并感到困惑.然后从项目本身加载库:

Finally I found a working solution (for Ant 1.7.1 at least). First you have to remove ant-jsch.jar from ANT_HOME/lib as Ant complains about it and gets confused. Then load libraries from the project itself:

<available property="ant-jsch.present" file="${ant.home}/lib/ant-jsch.jar"/>
<fail if="ant-jsch.present" message="Please remove ant-jsch.jar from ANT_HOME/lib see [http://ant.apache.org/faq.html#delegating-classloader]"/>

<path id="jsch.path">
    <pathelement location="lib/ant-jsch.jar" />
    <pathelement location="lib/jsch-0.1.44.jar" />
</path>

<taskdef name="scp" classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp" classpathref="jsch.path" />
<taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec" classpathref="jsch.path" />

这篇关于有没有办法从 build.xml 中指定本地 jsch.jar 的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:59