Java ANT - 无法加载依赖类 com/jcraft/jsch/Logger
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21231283/
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 - Could not load a dependent class com/jcraft/jsch/Logger
提问by kete nefrega
I have a problem with my Ant script.
我的 Ant 脚本有问题。
I need to copy a file to Linux server
我需要将文件复制到 Linux 服务器
<copy file="../Ant/lib/jsch-0.1.50.jar" tofile="${ant.home}/lib/jsch-0.1.50.jar" />
<scp todir="${server.user}:${server.password}@${server.dev}:${server.dev.dir.config}" trust="true" verbose="true">
<fileset dir="${src.home}/Config/">
<include name="**/*" />
</fileset>
</scp>
File is copied correctly, but I receive this error:
文件已正确复制,但我收到此错误:
BUILD FAILED
C:\dev.xml:179: Problem: failed to create task or type scp
Cause: Could not load a dependent class com/jcraft/jsch/Logger
It is not enough to have Ant's optional JARs
you need the JAR files that the optional tasks depend upon.
Ant's optional task dependencies are listed in the manual.
Action: Determine what extra JAR files are needed, and place them in one of:
-C:\Progs\eclipse\plugins\org.apache.ant_1.8.3.v201301120609\lib
-C:\Users\Administrator\.ant\lib
-a directory added on the command line with the -lib argument
How can I dynamically add this JAR in the Ant classloader?
如何在 Ant 类加载器中动态添加这个 JAR?
回答by AlexR
Add all dependencies of JSCH to lib
directory of ANT using similar <copy
tag.
lib
使用类似的<copy
标签将 JSCH 的所有依赖项添加到ANT 目录。
To find dependencies of JSCH check its documentation.
要查找 JSCH 的依赖项,请查看其文档。
回答by Exploring
The Exception itself is quite clear and points the reason of the problem:
Exception 本身已经很清楚了,并指出了问题的原因:
Action: Determine what extra JAR files are needed, and place them in one of:
-C:\Progs\eclipse\plugins\org.apache.ant_1.8.3.v201301120609\lib
-C:\Users\Administrator\.ant\lib
-a directory added on the command line with the -lib argument
Please check from Library Dependencies
请从库依赖项检查
jsch.jar 0.1.50 or later: sshexec and scp tasks (http://www.jcraft.com/jsch/index.html)
jsch.jar 0.1.50 或更高版本:sshexec 和 scp 任务 ( http://www.jcraft.com/jsch/index.html)
If you copy this lib in the ant lib it will solve the issue for the standalone Ant.
如果您将此库复制到 ant 库中,它将解决独立 Ant 的问题。
And for the case of Eclipse: Go into the Eclipse Preferences, in the Ant/Runtime entry, in the 'Classpath' tab. Use the button 'Add External Jars' to add your jsch.jar to Ant's classpath.
对于 Eclipse:进入 Eclipse Preferences,在 Ant/Runtime 条目中,在'Classpath' 选项卡中。使用“添加外部罐子”按钮将您的 jsch.jar 添加到 Ant 的类路径。
回答by Torben
After you have copied jsch-0.1.51.jar to /usr/share/ant/lib/ (or whatever directory you have), make the JAR file readable for all users, not just root. Don't be like me and spend half an hour trying to figure out why it doesn't work.
将 jsch-0.1.51.jar 复制到 /usr/share/ant/lib/(或您拥有的任何目录)后,让 JAR 文件对所有用户可读,而不仅仅是 root。不要像我一样花半个小时试图弄清楚为什么它不起作用。
回答by buttcmd
If you use Eclipse as IDE and you run ant from Eclipse is not enough to copy the needed jar file jsch-0.1.51.jar (or whatever version). It is alse needed to change the classpath ant uses when running.
如果您使用 Eclipse 作为 IDE 并且您从 Eclipse 运行 ant 不足以复制所需的 jar 文件 jsch-0.1.51.jar(或任何版本)。还需要更改蚂蚁在运行时使用的类路径。
If you use Windows -> Window > Preferences > Ant > Runtime If you use Mac -> Eclipse > Preferences > Ant > Runtime
如果您使用 Windows -> Window > Preferences > Ant > Runtime 如果您使用 Mac -> Eclipse > Preferences > Ant > Runtime
in the Classpath tab in "Ant home entries..." you must add the new jar.
在“Ant home entry...”的 Classpath 选项卡中,您必须添加新的 jar。
After that it works.
之后它就起作用了。