如何在构建中设置主类?
在 sbt run 后,我有多种主类选择。
我想设置一个主类,所以我在 build.sbt
中编写:
mainClass := Some("aMainClass")
但是 sbt 失败:
build.sbt:1: error: not found: value aMainClass
我也尝试过 project/Project.scala
文件:
import sbt._
class ExecutableProject(info: ProjectInfo) extends DefaultProject(info) {
override def mainClass = Some("aMainClass")
}
错误:
project/Project.scala:3: not found: type aMainClass
如何在构建中设置主类?
Upon sbt run
I have multiple choices of main class.
I would like to set a main class so I've writen in build.sbt
:
mainClass := Some("aMainClass")
But sbt fails with:
build.sbt:1: error: not found: value aMainClass
I've also tried with project/Project.scala
file :
import sbt._
class ExecutableProject(info: ProjectInfo) extends DefaultProject(info) {
override def mainClass = Some("aMainClass")
}
error :
project/Project.scala:3: not found: type aMainClass
How to set the main class in a build?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
主类必须与包完全限定:
这将适用于运行,并且在使用包任务时它将在清单中设置主类。这些任务的主类可以单独设置,如下所示:
注意:
不执行任何操作。如果您将其放入构建文件中,您将不会收到任何警告,表明它不执行任何操作。
The main Class must be fully qualified with the package:
This will work for run and it will set the Main-Class in the Manifest when using the package task. The main class for these tasks can be set separately as in:
Note:
does nothing. If you put this in your build file you will receive no warning that it does nothing.
据我所知,
sbt
期望您的项目中有一个完全限定的类/对象名称。例如,如果你的主类是这样的:那么你必须给你的主类这样:
你会得到一个类型错误,因为该类型不是简单地找到的。
As far as I know,
sbt
expects here a fully qualified class/object name within your project. For example, if your main class is like this:then you would have to give your main class like this:
You get a type error because that type is not simply found.
我的 sbt 版本是 sbt 1.5.4 (Ubuntu Java 11.0.11)。
我发现
mainClass in (Compile, run) :=Some("Hello")
在我的 build.sbt 中不起作用。我终于在 中找到了 1.x 版本的官方示例在这里
您可以将其添加到您的设置中。这对我有用。
但我不知道如何将这些命令集成到一个中。
My sbt version is sbt 1.5.4 (Ubuntu Java 11.0.11).
And I find
mainClass in (Compile, run) :=Some("Hello")
doesn't work in my build.sbt.I finally find the offical example for 1.x version in here
you can add it to your settings. It works for me.
But I don't know how to integrate those commands into one.