ANT - 无法加载依赖类com / jcraft / jsch / Logger

问题描述 投票:10回答:5

我的Ant脚本有问题。

我需要将文件复制到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>

文件已正确复制,但我收到此错误:

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

如何在Ant类加载器中动态添加此JAR?

java ant classloader
5个回答
11
投票

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

请从Library Dependencies查询

jsch.jar 0.1.50或更高版本:sshexec和scp任务(http://www.jcraft.com/jsch/index.html

如果您在ant lib中复制此lib,它将解决独立Ant的问题。

对于Eclipse的情况:进入Eclipse首选项,在Ant / Runtime条目中,在“Classpath”选项卡中。使用“Add External Jars”按钮将jsch.jar添加到Ant的类路径中。


2
投票

我找到了解决方案here


1
投票

如果您使用Eclipse作为IDE并且从Eclipse运行ant不足以复制所需的jar文件jsch-0.1.51.jar(或任何版本)。它还需要更改运行时ant使用的类路径。

如果您使用Windows - >窗口>首选项> Ant>运行时如果您使用Mac - > Eclipse>首选项> Ant>运行时

在“Ant home entries ...”的Classpath选项卡中,您必须添加新的jar。

之后它才有效。


0
投票

使用类似的lib标记将JSCH的所有依赖项添加到ANT的<copy目录中。

要查找JSCH的依赖项,请检查其文档。


0
投票

将jsch-0.1.51.jar复制到/ usr / share / ant / lib /(或您拥有的任何目录)之后,使JAR文件对所有用户都可读,而不仅仅是root用户。不要像我一样花半小时试图找出它为什么不起作用。

© www.soinside.com 2019 - 2024. All rights reserved.