java Ant 找不到我的 JAR 文件?尝试执行 sshexec 任务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3721890/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 03:09:51  来源:igfitidea点击:

Ant can't find my JAR file? Trying to do an sshexec task

javadeploymentant

提问by James

I'm trying to use the sshexec task for ANT on my OSX box, when I try to run it I get the error listed below. I've downloaded the jsch jar file from: http://www.jcraft.com/jsch/index.htmlversion jsch-0.1.43.jar

我试图在我的 OSX 机器上使用 ANT 的 sshexec 任务,当我尝试运行它时,我得到下面列出的错误。我已经从以下位置下载了 jsch jar 文件:http: //www.jcraft.com/jsch/index.html版本 jsch-0.1.43.jar

I placed that file into /usr/share/ant/lib and still the error occurs. any ideas?

我将该文件放入 /usr/share/ant/lib 中,但仍然发生错误。有任何想法吗?

thanks

谢谢

<target name="testme" depends="">
 <sshexec host="myhost1" username="${username}" command="ls -la" keyfile="${user.home}/.ssh/id_rsa" />
</target>

I get the following error:

我收到以下错误:

BUILD FAILED
/Users/jim/Code/myapp/deploy.xml:16: Problem: failed to create task or type sshexec
Cause: the class org.apache.tools.ant.taskdefs.optional.ssh.SSHExec was not found.
        This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
        -/usr/share/ant/lib
        -/Users/jim/.ant/lib
        -a directory added on the command line with the -lib argument

Do not panic, this is a common problem.
The commonest cause is a missing JAR.

UPDATE:::: I installed a new version of ANT from apache and put it in /usr/local and moved the jsch file into /usr/local/ant/lib and it fixes the error, however now I have a new one when I run it with: ant -f deploy.xml restart

更新:::: 我从 apache 安装了一个新版本的 ANT 并将其放在 /usr/local 并将 jsch 文件移动到 /usr/local/ant/lib 并修复了错误,但是现在我有了一个新版本我运行它: ant -f deploy.xml restart

BUILD FAILED
    /Users/jim/Code/myapp/deploy.xml:20: java.lang.NoSuchMethodError: com.jcraft.jsch.ChannelExec.setExtOutputStream(Ljava/io/OutputStream;)V
        at org.apache.tools.ant.taskdefs.optional.ssh.SSHExec.executeCommand(SSHExec.java:265)
        at org.apache.tools.ant.taskdefs.optional.ssh.SSHExec.execute(SSHExec.java:194)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1397)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1366)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1249)
        at org.apache.tools.ant.Main.runBuild(Main.java:801)
        at org.apache.tools.ant.Main.startAnt(Main.java:218)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Here is my diagnostic information:

这是我的诊断信息:

http://pastebin.org/877058

http://pastebin.org/877058

回答by pstanton

looks like a version compatibility issue, check the version of jsch matches the one supported by the ant version.

看起来是版本兼容性问题,检查jsch的版本是否与ant版本支持的版本匹配。

回答by James

Found the problem, when trying to fix the old ant version I had this file left over from my debugging attempts: /Library/Java/Extensions/jsch-0.1.8.jar

发现问题,当我尝试修复旧的 ant 版本时,我的调试尝试留下了这个文件:/Library/Java/Extensions/jsch-0.1.8.jar

I removed that guy and all is well

我删除了那个人,一切都很好

回答by Buminda

Download jsch-0.1.44.jarand make sure trust="true"is set.

下载jsch-0.1.44.jar并确保trust="true"已设置。

回答by Sujith

Make sure that you give trust="true"

确保你给予 trust="true"

<sshexec trust="true"
           host="host_ip"        
           verbose="true/false"
           username="UserName"
           keyfile="KeyFile_location"                     
           command="some_command">
</sshexec>