richsoni
richsoni

Reputation: 4278

Scala Newbie Multiple Files

I am new to Scala, and I cannot seem to find this information. Currently I have 2 files: ClassA.scala and MyMain.scala. When I run >scalac *.scala it compiles both files perfectly fine. However, when I run > scala MyMain.scala I get an error saying "not found: type ClassA". Is there anything special I have to do to include a class in another file?

Upvotes: 0

Views: 2918

Answers (2)

Brian
Brian

Reputation: 20285

You need to tell scala the classpath to the classes you are trying to load. You can do this with scala -classpath or the shorter scala -cp. So, for your example if the class files are in the current directory it would be scala -cp . MyMain. If you need to add more paths to the classpath you can separate them with a colon. e.g. scala -cp .:dir:otherdir MyMain.

Upvotes: 3

Jim Barrows
Jim Barrows

Reputation: 3634

You need to have both classes on your classpath. The "scala MyMain.scala" puts the MyMain.scala on the classpath, but not the ClassA. scala MyMain.scala -classpath ClassA.scala should do the trick. See the getting started page for more details.

Upvotes: 1

Related Questions