如何修复 SBT 0.11 找不到我的应用程序的主类?
我创建了一个只有一个源代码文件的 SBT 0.11 项目:
object HelloWorld extends App {
println("Hello, world!")
}
当尝试使用 SBT 运行应用程序时,我收到“java.lang.RuntimeException:未检测到主类”。
如何定义主类?
我已使用以下 Build.scala
的“完整配置”:
import sbt._
object MyBuild extends Build {
lazy val HelloWorld = Project("HelloWorld ", file("src"))
}
以及以下 build.sbt
:
name := "HelloWorld"
version := "1.0"
scalaVersion := "2.9.1"
I've created an SBT 0.11 project of an only one source code file (yet):
object HelloWorld extends App {
println("Hello, world!")
}
When try to run
the application with SBT, I get "java.lang.RuntimeException: No main class detected".
How do I define the main class?
I have used "full configuration" with the folowing Build.scala
:
import sbt._
object MyBuild extends Build {
lazy val HelloWorld = Project("HelloWorld ", file("src"))
}
And the following build.sbt
:
name := "HelloWorld"
version := "1.0"
scalaVersion := "2.9.1"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将: 替换
为:
Try replacing:
with:
Project
的第二个参数指示该项目的基目录是什么,假设您有很多项目。如果源代码的路径是HelloWorld\src\src\main\scala\HelloWorld.scala
,那么原始行就可以工作。问题是......第二个参数不指向源代码。它指向该项目。例如,您会看到它可能在您尝试使用原始配置时创建了目录
HelloWorld\src\target
。Project
's second parameter indicate what is the base directory of that project, which assumes you have many projects. If the path to your source code wasHelloWorld\src\src\main\scala\HelloWorld.scala
, then that original line would work.The thing is... that second parameter does not point to the source code. It points to the project. For example, you'd see it probably created the directory
HelloWorld\src\target
at the time you tried to use the original configuration.