Search code examples
scalaapache-commons-net

How to use apache commons (or any other library not part of the jdk) from Scala


Seems like this should be simple, but I'm not a java guy. I was going to try and use the apache commons ftp component (org.apache.commons.net.ftp), but I don't know how to make it accessible to my scala code.

At the moment, I've just tried dropping the package into a directory, starting the scala repl from that directory, and issued: import org.apache.commons.* I'm told that apache is not a member of package org, which I assume to mean it can't find the code.

This really seems like it ought to be easy, but any suggestions would be appreciated.


Solution

  • You need to add the jar into the class path. From REPL, that is done like so:

    scala -classpath some.jar
    

    If you are building a project, you might want to consider using a build tool like sbt (http://www.scala-sbt.org/) which allows you to specify dependencies.