3

I haven't worked with java/scala a lot, so my problem might be very obvious, but here it is:

I'm working on a scala program, and I want to import from a .jar file (filename.jar) in a sub-directory. I figure that this will work:

import sub.filename._

But I get the error: "Object filename is not a member of package sub."

So I try simply moving the jar file to the same directory as the scala program:

import filename._

And I get: "not found: object filename"

I'd appreciate any help.

sorowd
  • 114
  • 3
  • are you adding the jar file to your classpath or path, i forgot what it's called in java/scala? – Alex Jun 21 '11 at 17:59
  • thank you! That seems to be the problem. Editing my classpath environment variable worked--I assume there's an easy way to alter classpath for the scope of the program – sorowd Jun 21 '11 at 18:10
  • Both the Java and Scala executables take a -cp argument with a list of jars to add to the classpath. You might want to take a look at SBT if you're going to be using Scala as it streamlines much of this type of thing. Cheers! – Janx Jun 21 '11 at 18:16

2 Answers2

4

That doesn't work. You import things from packages, not directories. If you have a JAR somewhere, you need to start Scala with the classpath parameter pointing to all JARs you want access to.

Daniel C. Sobral
  • 295,120
  • 86
  • 501
  • 681
3

ok, so i am going to change my comment into an answer:

add the jar file to your classpath :)

Alex
  • 2,342
  • 1
  • 18
  • 30