ubuntu20.04 自带scala 解释器scala 脚本问题

 ubuntu20.04默认的scala 版本是2.11.12

$ scala
Welcome to Scala 2.11.12 (OpenJDK 64-Bit Server VM, Java 11.0.16).
Type in expressions for evaluation. Or try :help.

scala> println("hello,world");
hello,world

scala> :quit

报错提示
$ scala hello.scala 
error: Compile server encountered fatal condition: javax/tools/DiagnosticListener
java.lang.ClassNotFoundException: javax.tools.DiagnosticListener
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at scala.tools.util.PathResolverBase$Calculated$.javaBootClasspath(PathResolver.scala:277)
	at scala.tools.util.PathResolverBase$Calculated$.basis(PathResolver.scala:283)
	at scala.tools.util.PathResolverBase$Calculated$.containers$lzycompute(PathResolver.scala:293)
	at scala.tools.util.PathResolverBase$Calculated$.containers(PathResolver.scala:293)
	at scala.tools.util.PathResolverBase.containers(PathResolver.scala:309)
	at scala.tools.util.PathResolver.computeResult(PathResolver.scala:341)
	at scala.tools.util.PathResolver.computeResult(PathResolver.scala:332)
	at scala.tools.util.PathResolverBase.result(PathResolver.scala:314)
	at scala.tools.nsc.backend.JavaPlatform$class.classPath(JavaPlatform.scala:28)
	at scala.tools.nsc.Global$GlobalPlatform.classPath(Global.scala:115)
	at scala.tools.nsc.Global.scala$tools$nsc$Global$$recursiveClassPath(Global.scala:131)
	at scala.tools.nsc.Global$GlobalMirror.rootLoader(Global.scala:64)
	at scala.reflect.internal.Mirrors$Roots$RootClass.(Mirrors.scala:307)
	at scala.reflect.internal.Mirrors$Roots.RootClass$lzycompute(Mirrors.scala:321)
	at scala.reflect.internal.Mirrors$Roots.RootClass(Mirrors.scala:321)
	at scala.reflect.internal.Mirrors$Roots$EmptyPackageClass.(Mirrors.scala:330)
	at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass$lzycompute(Mirrors.scala:336)
	at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass(Mirrors.scala:336)
	at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass(Mirrors.scala:276)
	at scala.reflect.internal.Mirrors$RootsBase.init(Mirrors.scala:250)
	at scala.tools.nsc.Global.rootMirror$lzycompute(Global.scala:73)
	at scala.tools.nsc.Global.rootMirror(Global.scala:71)
	at scala.tools.nsc.Global.rootMirror(Global.scala:39)
	at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(Definitions.scala:257)
	at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(Definitions.scala:257)
	at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1390)
	at scala.tools.nsc.Global$Run.(Global.scala:1242)
	at scala.tools.nsc.StandardCompileServer.session(CompileServer.scala:151)
	at scala.tools.util.SocketServer$$anonfun$doSession$1$$anonfun$apply$1.apply(SocketServer.scala:74)
	at scala.tools.util.SocketServer$$anonfun$doSession$1$$anonfun$apply$1.apply(SocketServer.scala:74)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
	at scala.Console$.withOut(Console.scala:65)
	at scala.tools.util.SocketServer$$anonfun$doSession$1.apply(SocketServer.scala:74)
	at scala.tools.util.SocketServer$$anonfun$doSession$1.apply(SocketServer.scala:69)
	at scala.tools.nsc.io.Socket.applyReaderAndWriter(Socket.scala:49)
	at scala.tools.util.SocketServer.doSession(SocketServer.scala:69)
	at scala.tools.util.SocketServer.loop$1(SocketServer.scala:85)
	at scala.tools.util.SocketServer.run(SocketServer.scala:97)
	at scala.tools.nsc.CompileServer$$anonfun$execute$2$$anonfun$apply$mcZ$sp$1.apply$mcZ$sp(CompileServer.scala:218)
	at scala.tools.nsc.CompileServer$$anonfun$execute$2$$anonfun$apply$mcZ$sp$1.apply(CompileServer.scala:213)
	at scala.tools.nsc.CompileServer$$anonfun$execute$2$$anonfun$apply$mcZ$sp$1.apply(CompileServer.scala:213)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
	at scala.Console$.withOut(Console.scala:53)
	at scala.tools.nsc.CompileServer$$anonfun$execute$2.apply$mcZ$sp(CompileServer.scala:213)
	at scala.tools.nsc.CompileServer$$anonfun$execute$2.apply(CompileServer.scala:213)
	at scala.tools.nsc.CompileServer$$anonfun$execute$2.apply(CompileServer.scala:213)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
	at scala.Console$.withErr(Console.scala:80)
	at scala.tools.nsc.CompileServer$.execute(CompileServer.scala:212)
	at scala.tools.nsc.CompileServer$.main(CompileServer.scala:180)
	at scala.tools.nsc.CompileServer.main(CompileServer.scala)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at scala.reflect.internal.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:70)
	at scala.reflect.internal.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:31)
	at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:101)
	at scala.reflect.internal.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:70)
	at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101)
	at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:22)
	at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:39)
	at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:29)
	at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:39)
	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:65)
	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)
$ scala

解决办法:

我有同样的问题,并通过升级到Scala 2.12.6修复它:

sudo apt remove scala-library scala
wget www.scala-lang.org/files/archive/scala-2.12.6.deb
sudo dpkg -i scala-2.12.6.deb

你可能感兴趣的:(scala,scala,java)