【问题标题】:ANT - Could not load a dependent class com/jcraft/jsch/LoggerANT - 无法加载依赖类 com/jcraft/jsch/Logger
【发布时间】:2018-09-10 00:49:15
【问题描述】:

我的 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


    【解决方案1】:

    异常本身很清楚,指出问题的原因:

    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 库中,它将解决独立 Ant 的问题。

    对于 Eclipse:进入 Eclipse Preferences,在 Ant/Runtime 条目中,在“Classpath”选项卡中。使用“添加外部罐子”按钮将您的 jsch.jar 添加到 Ant 的类路径中。

    【讨论】:

      【解决方案2】:

      将 jsch-0.1.51.jar 复制到 /usr/share/ant/lib/(或您拥有的任何目录)后,让所有用户都可以读取 JAR 文件,而不仅仅是 root。不要像我一样花半个小时来弄清楚为什么它不起作用。

      【讨论】:

        【解决方案3】:

        我找到了解决方案here

        【讨论】:

          【解决方案4】:

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

          如果你使用 Windows -> Window > Preferences > Ant > Runtime 如果你使用 Mac -> Eclipse > Preferences > Ant > Runtime

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

          之后它就可以工作了。

          【讨论】:

            【解决方案5】:

            使用类似的&lt;copy标签将JSCH的所有依赖添加到ANT的lib目录。

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

            【讨论】:

              猜你喜欢
              • 2013-05-20
              • 2013-10-23
              • 1970-01-01
              • 1970-01-01
              • 2016-09-26
              • 1970-01-01
              • 1970-01-01
              • 2016-02-09
              • 1970-01-01
              相关资源
              最近更新 更多