Jonas
Jonas

Reputation: 129075

How do I import a Java package in Scala?

I have created a jar-file with a compiled Java class. Now I want to import it in Scala. But it doesn't work.

The package name is se.mydomain.testproj and here is a small Scala application:

object TestCrypt {

    import se.mydomain.testproj._

    def main(args: Array[String]) {
      println("Hello")
    }
}

I use Eclipse and have added the jar file to the Build Path.

In Eclipse, I get the error: not found: value se

How can I import Java classes from a Jar file in Scala?

Upvotes: 3

Views: 2376

Answers (1)

dhg
dhg

Reputation: 52701

I do this all the time in Eclipse, so it definitely works. Do you see the jar in the Referenced Libraries of the project? Do you have the package name right?

Also, an import in the object as opposed to the top of the file should be fine.

Upvotes: 2

Related Questions