【问题标题】:Unable to run a standlone scala file无法运行独立的 scala 文件
【发布时间】:2021-12-24 15:09:21
【问题描述】:

我正在关注 Odersky 编写的 Programming in Scala 书中的示例,但我无法使用 scala hello.scala 运行简单的独立 scala 文件。当我这样做时,我得到这个错误:

Error: Could not find or load main class hello.scala
Caused by: java.lang.ClassNotFoundException: hello.scala

我正在使用 scala3。

这是我正在运行的文件和命令的状态。

【问题讨论】:

  • 您使用的是哪个版本的 Scala 3?我认为直到 Scala 3.1 才重新添加对 scala hello.scala 的支持。
  • 请不要使用截图发布代码或成绩单;因为我们不能自己复制粘贴来尝试,所以它更难为您提供帮助。

标签: scala scripting


【解决方案1】:

如果您按照the documentation 中的步骤操作,您会发现您需要在运行文件之前对其进行编译。

如果你运行:

scalac hello.scala
scala hello

你应该得到你想要的结果。

【讨论】:

    【解决方案2】:

    您可以考虑使用来自 virtuslab 的名为“scala-cli”的新(和出色)工具:https://scala-cli.virtuslab.org/

    【讨论】:

    • 我不会(截至 2021 年 11 月)向语言新手推荐这个;它仍在开发中。
    猜你喜欢
    • 2017-05-07
    • 2017-01-04
    • 2017-04-10
    • 2015-11-23
    • 1970-01-01
    • 1970-01-01
    • 2014-01-31
    • 2017-08-14
    • 1970-01-01
    相关资源
    最近更新 更多