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.

3
  • are you adding the jar file to your classpath or path, i forgot what it's called in java/scala? Commented Jun 21, 2011 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 Commented Jun 21, 2011 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! Commented Jun 21, 2011 at 18:16

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

add the jar file to your classpath :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.