没有这样的方法jsch.JSch.setLogger

时间:2013-06-13 18:11:13

标签: java sftp google-code net-sftp

当我调用getSftpUtil()时会发生以下行为。我还确保所有适当的jar都在maven项目的外部库中,并且可以在项目的WEB-INF/lib文件夹中找到

net.sf.opensftp.SftpUtil util = SftpUtilFactory.getSftpUtil();

栈跟踪

SftpUtilFactory: Trying to get SftpUtil class name from the system property net.sf.opensftp.SftpUtil
SftpUtilFactory  - Trying to get SftpUtil class name from the system property net.sf.opensftp.SftpUtil
SftpUtilFactory: The system property net.sf.opensftp.SftpUtil is not set.
SftpUtilFactory  - The system property net.sf.opensftp.SftpUtil is not set.
SftpUtilFactory: Use the default one.
SftpUtilFactory  - Use the default one.

Caused by: java.lang.NoSuchMethodError: com.jcraft.jsch.JSch.setLogger(Lcom/jcraft/jsch/Logger;)V
at net.sf.opensftp.impl.SftpUtil.<clinit>(SftpUtil.java:110)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at net.sf.opensftp.SftpUtilFactory.getSftpUtil(SftpUtilFactory.java:184)

2 个答案:

答案 0 :(得分:0)

好吧,我猜你错过了这种依赖或正确的版本:

<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.49</version> <!--latest version -->

答案 1 :(得分:0)

基于jcraft的change log,setLogger是jsch-0.1.30中添加到JSch.java的方法。所以WEB-INF / lib下的jar应该是旧版本。

你可以运行

mvn dependency:tree

查看哪些依赖项正在使用旧版本,然后使用以下内容将其排除:

<dependency>
    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <version>...</version>
    <exclusions>
        <exclusion>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
        </exclusion>
    </exclusions>
</dependency>

您可能有另一个依赖项引用了更新版本的jsch,因此您的问题应该在此时解决。但是,如果不是这种情况,可以将其添加到pom.xml:

<dependency>
    <groupId>com.jcraft</groupId>
    <artifactId>jsch</artifactId>
    <version>0.1.50</version>
</dependency>