我对你如何导入包及其类非常困惑。 我有两个scala项目,具有以下目录结构:
project1/ src/ main/ scala/ utils/ some_file.scala worksheet/ learning.sc project2/ * seemingly the same as project 1 *some_file.scala的内容:
package utils class InterestingClass { override def toString(): String = "I should be interesting" }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 }当我创建project1/src/main/scala/ ,在Eclipse中我右键单击main.scala ,它显示为src下面的包并选中: Build Path > Use As Source Folder ,然后在Eclipse中“删除” src文件夹。 project2实际上是我作为在线课程的一部分下载的一个项目所以我想在.project文件或我需要调整的.settings文件夹中有一些配置,因为project1中的learning.sc自动编译并按预期生成两个输出包括I should be interesting但在project2它没有和行import utils.InterestingClass显示not found: object utils的错误not found: object utils 。
我想在构建路径中有一个微妙的不同,但我找不到它,错误信息不会让我更进一步。 有关如何调试导入错误的任何提示? 查看构建路径,它们看起来是正确的(都有project1/src/main/scala或project2/src/main/scala )。
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).
最满意答案
我刚刚打开它,现在很好。 必须是Eclipse SDK的Scala IDE构建中的错误
构建ID:3.0.4-2.11-20140520-1158-Typesafe
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
更多推荐
发布评论