Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 393
Jonas Avatar asked Feb 12 '26 00:02

Jonas


1 Answers

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.

like image 80
dhg Avatar answered Feb 14 '26 13:02

dhg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!