Apache Mina Core不兼容的类更改错误

时间:2018-06-18 20:37:00

标签: java

我正在使用基于Java的FTP服务器,我可以将其嵌入到另一个项目中。我使用Apache mina库作为FTP服务器。我可以启动服务器,但当我尝试连接到它时,我收到此错误:

Exception in thread "pool-1-thread-1" java. lang.IncompatibleClassChangeError
at org.apache.mina.core.filterchain.DefaultIoFilterChain.register(DefaultIoFilterChain.java:276)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.addLast(DefaultIoFilterChain.java:175)
at org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder.buildFilterChain(DefaultIoFilterChainBuilder.java:452)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.addNow(AbstractPollingIoProcessor.java:430)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.handleNewSessions(AbstractPollingIoProcessor.java:412)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$200(AbstractPollingIoProcessor.java:56)
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:885)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

我已经对错误原因做了一些阅读。 This site至少暗示它是Apache Mina代码的问题。

我使用Apache Mina核心库 v2.019 和Apache FTP库 v1.1.1 ,这两者都是我能找到的最新版本

这是我的服务器实现:

public FTPServer(final String ipadress, final int port){   
    FtpServerFactory serverFactory = new FtpServerFactory();
    ListenerFactory listenerfactory = new ListenerFactory();

    listenerfactory.setDataConnectionConfiguration( 
        new DataConnectionConfigurationFactory().createDataConnectionConfiguration()
    );

    ConnectionConfigFactory connection = new ConnectionConfigFactory();
    connection.setMaxLoginFailures(10);
    connection.setLoginFailureDelay(5);
    connection.setAnonymousLoginEnabled(false);

    // set the ip address of the listener
    listenerfactory.setServerAddress(ipaddress);

    // set the port of the listener
    if (port == 0){
        listenerfactory.setPort(PORT);
    }
    else {
        listenerfactory.setPort(port);
        // replace the default listener
        serverFactory.addListener("default", listenerfactory.createListener());

serverFactory.setConnectionConfig(connection.createConnectionConfig());
    }

    PropertiesUserManagerFactory userManagerFactory = new 
    PropertiesUserManagerFactory();
    userManagerFactory.setFile(new File("myusers.properties"));
    userManagerFactory.setPasswordEncryptor(new SaltedPasswordEncryptor());
    UserManager um = userManagerFactory.createUserManager();
    BaseUser user = new BaseUser();

    user.setName("test");
    user.setPassword("test");
    user.setHomeDirectory("");

    try {
      um.save(user);
    } catch (FtpException e1) {
        // TODO Auto-generated catch block
        this.stopServer();
        e1.printStackTrace();
    }

    serverFactory.setUserManager(um);
    server = serverFactory.createServer();
    //this.StartServer();
}

1 个答案:

答案 0 :(得分:0)

我从头开始,并使用Apache示例代码创建FTP服务器。我将其粘贴在Main.java中的静态方法中,并删除了对服务器代码的引用。我无法重现我的错误。然后,我将代码的一部分复制到新的静态方法中,直到获得与原始代码相同的代码,并且无法重现原始故障。然后,我将代码还原到Main.java,并删除了对静态方法的调用。我仍然无法重现该错误。我以为这是NetBeans的问题,在几个清理和构建过程中仍然存在,但是在引入新的Apache示例代码时已解决。