0

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).

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
AJP
  • 26,547
  • 23
  • 88
  • 127
  • @om-nom-nom why did you remove the import and import-error tags? I think this question is exactly about those issues surely? I'm less certain it's specifically about the scala-ide? Using the command line `sbt` also presents similar but slightly different problems. – AJP Jul 15 '14 at 10:13
  • those tags are extremely vague and chances are low that users subscribed to them can resolve problem highly specific to **scala** and in particular, eclipse. You haven't told anything about sbt check, thus I *assumed* that problem might be specific to scala plugin. Or, speaking in a venn diagram terms, it may look [this](http://take.ms/TjOmc). – om-nom-nom Jul 15 '14 at 11:46
  • Hahaha, that venn is perfect. Thanks @om-mom-mom. Yeah I unfortunately didn't know where to progress from here but will put in the sbt info and will now start searching for hints in Scala-IDE. Do you think it might be an incorrect build path or is that completely the wrong track? Thanks for your time so far, much appreciated. – AJP Jul 16 '14 at 04:56
  • Suggest you use Intellij with sbt, much nicer than Eclipse. – samthebest Jul 16 '14 at 10:08

2 Answers2

1

I just opened it up again and now it's fine. Must be a bug in Scala IDE build of Eclipse SDK

Build id: 3.0.4-2.11-20140520-1158-Typesafe

AJP
  • 26,547
  • 23
  • 88
  • 127
0

If project2 needs classes defined in project1 you need to add it as a dependency in the settings of project2. You can do that by navigating to project properties/Java Build Path and then adding the dependency.

Iulian Dragos
  • 5,692
  • 23
  • 31