javascaladebianscala-shell

scala EPFL Exception in thread "main" java.lang.NoClassDefFoundError: javax/script/Compilable


I am a complete noob on Scala and JVM programming. The team I recently joined uses scala to build programs to be run on Spark. The stack at work is stable and functional but its complexity does not match the needs I have at home: merely the one to have a functional scala shell to get a bit more familiar with the language, try things, get the syntax right before adding any "environmental complexity"

[NOTE] I just want something dumb in the same vein of this documentation (so, please not answer based on compilers, sbt, IDE, etc etc)

david@ripper$ java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-2~deb9u1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
david@ripper$ scala -version 
Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL

Here is what I get when lunching the shell

david@ripper$ scala 
Exception in thread "main" java.lang.NoClassDefFoundError: javax/script/Compilable
at scala.tools.nsc.interpreter.ILoop.createInterpreter(ILoop.scala:118)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:911)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:909)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:909)
at scala.reflect.internal.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:97)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:909)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:74)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:87)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:98)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:103)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

It seems like a classical issue I first though related with the fact that I have an Oracle java 11 installed on my system. However, I thought that I made openjdk8 is the default, system-wide JRE with this:

update-alternatives --config java
Il existe 2 choix pour l'alternative java (qui fournit /usr/bin/java).
Sélection   Chemin Priorité  État
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-oracle/bin/java             1091      mode automatique
  1            /usr/lib/jvm/java-11-oracle/bin/java             1091      mode manuel
* 2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      mode manuel

What am I missing. Isn't scala using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java. I am using the default scala package provided in Debian 9


Solution

  • Turns out, update-alternatives --config java did not change the JAVA_HOME of the user's PATH (which still pointed to java11). It seems that the scala-shell does not use the system's default JRE but, rather, the one .bashrc (in my case .zshrc) points to.