scala
的手册页说它应该能够运行“顶级对象或脚本文件”,但我无法让后者工作。
# This works:
scalac Example.scala && scala Example
# ...but this doesn't:
scala Example.scala
错误信息总是
error: Compile server encountered fatal condition: javax/tools/DiagnosticListener java.lang.ClassNotFoundException: javax.tools.DiagnosticListener
...但是代码很简单:
object Exmple {
def main(args: Array[String]): Unit = {
System.out.println("Example")
}
}
最佳答案
由于您使用的是 Scala 2.11.12 和 JDK 11,您可能会遇到问题 Could not launch Scala 2.10.7, 2.11.12 REPL with Java 11 (without -nobootcp -nc
workaround) #10603解决方法是
scala -nobootcp -nc Example.scala
作为在 Linux 中使用 apt 安装 Scala 的替代方案,请考虑 One-click install for Scala通过coursier
curl -fLo cs https://git.io/coursier-cli-"$(uname | tr LD ld)"
chmod +x cs
./cs setup
rm -f cs
应该安装 Scala 开发所需的所有组件。
提到 scala-runners 的相关答案:https://stackoverflow.com/a/64231391/5205022
关于Scala 文件编译但不会在 Scala 2.11.12 和 JDK 11 上作为脚本运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66164232/