xml中指定本地jsch

xml中指定本地jsch

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

问题描述

build.xml包含< scp> < sshexec> 任务,所以我提供了jsch.jar和
同一目录中的其他库以及build.xml。



以下taskdef:

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

抛出错误

 无法找到类org.apache.tools.ant.taskdefs.optional.ssh.Scp 
所需的类:com / jcraft / jsch / UserInfo

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





但无法得到关于类加载器的答案。

解决方案

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

 < available property =ant-jsch.presentfile =$ {ant 。家里} /lib/ant-jsch.jar/> 
< fail if =ant-jsch.presentmessage =请从ANT_HOME / lib中删除ant-jsch.jar,请参阅[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 =scpclassname =org.apache.tools.ant.taskdefs.optional.ssh.Scpclasspathref =jsch.path/>
< taskdef name =sshexecclassname =org.apache.tools.ant.taskdefs.optional.ssh.SSHExecclasspathref =jsch.path/>


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

The following taskdef:

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

throws an error

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

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.

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.

解决方案

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:58
查看更多