I'm very confused about how you import packages and their classes. I have two scala projects with the following directory structures:
project1/
src/
main/
scala/
utils/
some_file.scala
worksheet/
learning.sc
project2/
* seemingly the same as project 1 *
The contents of some_file.scala:
package utils
class InterestingClass {
override def toString(): String = "I should be interesting"
}
The contents of learning.sc:
package worksheet
import utils.InterestingClass
object learning {
println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
println(new InterestingClass()) //> I should be interesting
}
When I created project1/src/main/scala/
, in Eclipse I right clicked main.scala
that was showing as a package underneath src
and selected: Build Path > Use As Source Folder
, and in Eclipse then "deleted" the src
folder. project2
is actually a project I have downloaded as part of an online course so I guess there's some config in the .project
file or the .settings
folder that I need to tweak because learning.sc
in project1 auto compiles as expected and produces the two outputs including I should be interesting
but in project2
it does not and the line import utils.InterestingClass
shows the error not found: object utils
.
I guess there's a subtle different in the build paths but I can't find it and the error message doesn't get me much further. Any tips on how to debug import errors? Looking at the build paths, they look correct (both have project1/src/main/scala
or project2/src/main/scala
).