Search code examples
tomcatftpembed

Embed the Apache FTPServer (Mina) in Tomcat


I'm trying to run a FTP server in my web application.
I've started here : http://mina.apache.org/ftpserver-project/embedding_ftpserver.html and put this in my FOM:

<dependency>
    <groupId>org.apache.ftpserver</groupId>
    <artifactId>ftpserver-core</artifactId>
    <version>1.0.6</version>
</dependency>

<dependency>
    <groupId>org.apache.ftpserver</groupId>
    <artifactId>ftplet-api</artifactId>
    <version>1.0.6</version>
</dependency>

<dependency>
    <groupId>org.apache.mina</groupId>
    <artifactId>mina-core</artifactId>
    <version>3.0.0-M2</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.18</version>
</dependency>

But when starting my Tomcat I got this error:

Mar 11, 2016 2:49:30 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Mar 11, 2016 2:49:30 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/sagitarii] startup failed due to previous errors

...and my application stop.

what I'm doing wrong?


Solution

  • As I said in my comment, the class org/apache/mina/filter/executor/OrderedThreadPoolExecutor is not in the 3.0 M2 and I can't find any sample code to replace the one I found:

        PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
        UserManager userManager = userManagerFactory.createUserManager();
    
        BaseUser user = new BaseUser();
        user.setName("cache");
        user.setPassword("cache");
        user.setHomeDirectory( PathFinder.getInstance().getPath() + "/cache/" );
        userManager.save(user);
    
        BaseUser scientist = new BaseUser();
        scientist.setName("storage");
        scientist.setPassword("storage");
        scientist.setHomeDirectory( PathFinder.getInstance().getPath() + "/storage/" );
        userManager.save(scientist);
    
        ListenerFactory listenerFactory = new ListenerFactory();
        listenerFactory.setPort( serverPort );
    
        FtpServerFactory factory = new FtpServerFactory(); // <<-- ERROR HERE !!
        factory.setUserManager(userManager);
        factory.addListener("default", listenerFactory.createListener());
    
        server = factory.createServer();
        server.start();
    

    Changed to 2.0.13 and it started to work.