SBT:从命令行运行特定的主方法

发布于 2025-01-19 07:31:45 字数 548 浏览 7 评论 0原文

我有几种用@main注释的方法,即使在彻底查看了SBT文档之后,它也完全击败了我如何从终端运行其中一种方法。我只能找到如何指定主要类中的源文件。但是,我的项目仅包含一个文件,因此这并不是很有帮助。

假设我有以下内容(当然是项目的根目录):

├── root
│   └── src
│       └── main
│           └── scala
│               └── main.scala

main.scala看起来像这样:

object main:
  @main def foo(): Unit = ???
  @main def bar(): Unit = ???

是运行foo或<的唯一方法代码> bar 从外壳中以通过几个文件分发我的方法?

I have several methods annotated with @main and it totally beats me how to run one of them specifically from a terminal, even after thoroughly looking at the sbt documentation. All I can find is how to specify what source file my main class is in. My project contains only one file though, so this is not really helpful.

Assume I have the following (where root being the project's root directory of course):

├── root
│   └── src
│       └── main
│           └── scala
│               └── main.scala

and main.scala looks something like this:

object main:
  @main def foo(): Unit = ???
  @main def bar(): Unit = ???

Is the only way to run either foo or bar from a shell to distribute up my methods over several files? ????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岛歌少女 2025-01-26 07:31:45

您可以通过以下方式从 SBT shell 内部运行任一方法:

runMain foo

runMain bar

You may run either methods from inside SBT shell via:

runMain foo

or

runMain bar
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文