Jellicle
Jellicle

Reputation: 30286

Scala file compiles but won't run as script on Scala 2.11.12 and JDK 11

The man page for scala says it should be able to run either a "A top-level object or a script file," but I can't get the latter to work.

# This works:
scalac Example.scala && scala Example
# ...but this doesn't:
scala Example.scala

The error message is always

error: Compile server encountered fatal condition: javax/tools/DiagnosticListener java.lang.ClassNotFoundException: javax.tools.DiagnosticListener

...but the code is simply:

object Exmple {
  def main(args: Array[String]): Unit = {
    System.out.println("Example")
  }
}

Upvotes: 5

Views: 1835

Answers (1)

Mario Galic
Mario Galic

Reputation: 48430

Since you are using Scala 2.11.12 and JDK 11 you might be experiencing issue Could not launch Scala 2.10.7, 2.11.12 REPL with Java 11 (without -nobootcp -nc workaround) #10603 for which the workaround is

scala -nobootcp -nc Example.scala

As an alternative to installing Scala with apt in Linux consider One-click install for Scala via coursier

curl -fLo cs https://git.io/coursier-cli-"$(uname | tr LD ld)"
chmod +x cs
./cs setup
rm -f cs

which should install all the necessary components for Scala development.

Related answer that mentions scala-runners: https://stackoverflow.com/a/64231391/5205022

Upvotes: 7

Related Questions