Scala项目不会在Eclipse中编译; “找不到主类”。 [英] Scala project won't compile in Eclipse; "Could not find the main class."
问题描述
但是,如果一个项目包含更多的类,我收到找不到主类错误。
我已经尝试搜索解决方案,我发现:
Eclipse正在寻找Main $类,而不是Main类
*在调试配置下,我的主要类被正确地标识为mypackage.Main
*我的插件是最新的,推荐我的Eclipse版本
*清理,重启等等帮助。
同样的项目将使用scalac进行编译。
感谢任何有关如何解决这个问题的想法。 p>
编辑:MatthieuF建议我应该发布代码。
此代码段会产生错误。这不是最惯用的代码,但是我用这种方法来测试我的环境。我试过它作为单个文件和单独的文件。它可以与scalac一起工作。
import swing._
class HelloFrame extends Frame {
title =First program
contents = new Label(Hello,world!)
}
对象Hello {
val frame = new HelloFrame
def main(args:Array [String]):Unit = {
frame.visible = true
}
}
但是,如果我在Hello中嵌套HelloFrame的定义,它可以工作。这个代码段完美运行:
import swing._
对象你好{
class HelloFrame extends Frame {
title =First program
contents = new Label(Hello,world!)
}
val frame = new HelloFrame
def main(args:Array [String]):Unit = {
frame.visible = true
}
}
对我来说,问题是有一个构建错误(见问题选项卡)防止编译;哎呀!您看到错误的原因是,尽管编译失败步骤,运行宏仍在继续,并尝试运行它期望的类文件;它们不存在,因为存在构建错误阻止编译,所以它说它找不到Main(没有编译)。
构建完成时问题消失成功地,即错误是固定的。
我猜,理论上来说,您的构建可能还没有成功完成,没有列在问题中。
I have installed Eclipse 3.5.2 and today's Scala plugin from /update-current (that's Scala 2.8 final.) I can compile and run Scala projects consisting of a single singleton object that implements main().
But, if a project contains more classes, I receive the "Could not find the main class" error.
I have tried searching for the solution and I discovered:
Eclipse is correctly looking for the Main$ class, not the Main class
* under Debug Configurations, my main class is correctly identified as mypackage.Main
* my plugin is up to date and recommended for my version of Eclipse
* cleaning, restarting etc. doesn't help.
The same project will compile with scalac.
Thanks for any ideas on how to solve this.
EDIT: MatthieuF suggested I should post the code.
This snippet produces an error. It's not the most idiomatic code, but I wrote it that way to test my environment. I tried it as a single file and as separate files. It DOES work with scalac.
import swing._
class HelloFrame extends Frame {
title = "First program"
contents = new Label("Hello, world!")
}
object Hello {
val frame = new HelloFrame
def main(args : Array[String]) : Unit = {
frame.visible = true
}
}
BUT, if I nest the definition of HelloFrame within Hello, it works. This snippet runs perfectly:
import swing._
object Hello {
class HelloFrame extends Frame {
title = "First program"
contents = new Label("Hello, world!")
}
val frame = new HelloFrame
def main(args : Array[String]) : Unit = {
frame.visible = true
}
}
For me, the problem was that there was a build error (see Problems tab) which was preventing compilation; oops! The reason you see the error is that the run macro proceeds despite the failed compilation step, and attempts to run class files it expects to be there; they don't exist because there was a build error preventing compilation, so it says it can't find Main (not compiled).
Problem goes away when build can complete successfully, i.e. errors are fixed.
I guess, theoretically, there may be more complicated reasons your build is not completing successfully that are not listed in Problems.
这篇关于Scala项目不会在Eclipse中编译; “找不到主类”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!