Java Ant scp 任务不起作用,即使在 ant/lib 上使用 jsch
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2374105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ant scp task not working, even with jsch on ant/lib
提问by Pablo Fernandez
I need to copy a war file via scp.
我需要通过 scp 复制一个战争文件。
I have added the jsch-0.1.42.jar
to $ANT_HOME/lib
but I'm still getting this error:
我已添加到jsch-0.1.42.jar
,$ANT_HOME/lib
但我仍然收到此错误:
Cause: the class org.apache.tools.ant.taskdefs.optional.ssh.Scp was not found. This looks like one of Ant's optional components.
原因:找不到类 org.apache.tools.ant.taskdefs.optional.ssh.Scp。这看起来像是 Ant 的可选组件之一。
This is the result of running ant -diagnostics
just in case:
这是ant -diagnostics
为了以防万一运行的结果:
采纳答案by gareth_bowles
This looks like your problem, from the top of the diagnostics:
从诊断的顶部来看,这看起来像是您的问题:
optional tasks : not available
可选任务:不可用
Your $ANT_HOME/lib directory is missing ant-jsch.jar, which is where your missing class comes from.
您的 $ANT_HOME/lib 目录缺少 ant-jsch.jar,这是您缺少的类的来源。
I'm not sure how this happened - I always install Ant from the ZIP file on the download site, which includes all the optional tasks. If you installed Ant from a Linux package, try checking to see if there is a separate package for the optional tasks.
我不确定这是怎么发生的 - 我总是从下载站点上的 ZIP 文件安装 Ant ,其中包括所有可选任务。如果您从 Linux 包安装 Ant,请尝试检查是否有用于可选任务的单独包。
Once you get the optional tasks installed, I would delete the old version of jsch.jar as @trashgod suggests.
一旦安装了可选任务,我会按照@trashgod 的建议删除旧版本的 jsch.jar。
回答by radistao
I had the same problem and fixed it!
Remember, you need BOTHant-jsch.jar
(native from ant or java installation) and updated jsch
(in my case it was jsch-0.1.46.jar
) in ant lib dir.
我遇到了同样的问题并修复了它!请记住,您需要两者ant-jsch.jar
(来自 ant 或 java 安装的本机)并在 ant lib 目录中更新jsch
(在我的情况下是jsch-0.1.46.jar
)。
You need to load the newest jsch.jar
from http://www.jcraft.com/jsch/and add to libs folder (but not replace ant-jsch.jar
).
您需要jsch.jar
从http://www.jcraft.com/jsch/加载最新的并添加到 libs 文件夹(但不是 replace ant-jsch.jar
)。
The mistake a lot of developers do:
很多开发者都会犯的错误:
ant-jsch.jar
out of date (in this case <scp> task is unknown for ant)- Adjust libraries versions, so
ant-jsch.jar
andjsch
are compatible. jsch
not exists or out of date in ant lib dir- Native
ant-jsch.jar
replaced withjsch
(i did it...)
ant-jsch.jar
过时(在这种情况下,<scp> 任务对于 ant 来说是未知的)- 调整库版本,因此
ant-jsch.jar
和jsch
兼容。 jsch
ant lib 目录中不存在或已过期- Native
ant-jsch.jar
替换为jsch
(我做到了...)
In last 2 cases ant knows scpcommand, but says it is not available.
在最后两种情况下,ant 知道scp命令,但说它不可用。
回答by Sree Lakshmi
I added ant-jsch and jsch dependencies in maven pom.xml or including those two jars in build solved the issue.
我在 maven pom.xml 中添加了 ant-jsch 和 jsch 依赖项,或者在 build 中包含这两个 jars 解决了这个问题。