MSys2下的Scala - 无法初始化终端

时间:2015-07-30 21:27:28

标签: java windows scala msys2

我的环境是Windows 10 x64 / Scala 2.11.7 / Msys2最新版本。

从MSys2控制台运行Scala时,我看到以下内容:

$ scala
[ERROR] Terminal initialization failed; falling back to unsupported
java.lang.NoClassDefFoundError: Could not initialize class org.fusesource.jansi.internal.Kernel32
    at org.fusesource.jansi.internal.WindowsSupport.getConsoleMode(WindowsSupport.java:50)
    at jline.WindowsTerminal.getConsoleMode(WindowsTerminal.java:204)
    at jline.WindowsTerminal.init(WindowsTerminal.java:82)
    at jline.TerminalFactory.create(TerminalFactory.java:101)
    at jline.TerminalFactory.get(TerminalFactory.java:158)
    at jline.console.ConsoleReader.<init>(ConsoleReader.java:229)
    at jline.console.ConsoleReader.<init>(ConsoleReader.java:221)
    at jline.console.ConsoleReader.<init>(ConsoleReader.java:209)
    at scala.tools.nsc.interpreter.jline.JLineConsoleReader.<init>(JLineReader.scala:61)
    at scala.tools.nsc.interpreter.jline.InteractiveReader.<init>(JLineReader.scala:33)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$scala$tools$nsc$interpreter$ILoop$$instantiate$1$1.apply(ILoop.scala:865)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$scala$tools$nsc$interpreter$ILoop$$instantiate$1$1.apply(ILoop.scala:862)
    at scala.tools.nsc.interpreter.ILoop.scala$tools$nsc$interpreter$ILoop$$mkReader$1(ILoop.scala:871)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$15$$anonfun$apply$8.apply(ILoop.scala:875)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$15$$anonfun$apply$8.apply(ILoop.scala:875)
    at scala.util.Try$.apply(Try.scala:192)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$15.apply(ILoop.scala:875)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$15.apply(ILoop.scala:875)
    at scala.collection.immutable.Stream.map(Stream.scala:418)
    at scala.tools.nsc.interpreter.ILoop.chooseReader(ILoop.scala:875)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1$$anonfun$apply$mcZ$sp$2.apply(ILoop.scala:916)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:916)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:911)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:911)
    at scala.reflect.internal.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:97)
    at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:911)
    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)

Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_79).
Type in expressions to have them evaluated.
Type :help for more information.

scala>

从cmd.exe运行时,它按预期工作。为了调试这个问题,我尝试了以下Scala程序:

object Test extends App {
    println(org.fusesource.jansi.internal.WindowsSupport.getConsoleMode)
}

从Msys2运行时,会产生以下错误:

java.lang.UnsatisfiedLinkError: Could not load library. Reasons: [no jansi in java.library.path]
    at org.fusesource.hawtjni.runtime.Library.doLoad(Library.java:182)
    at org.fusesource.hawtjni.runtime.Library.load(Library.java:140)
    at org.fusesource.jansi.internal.Kernel32.<clinit>(Kernel32.java:37)
    at org.fusesource.jansi.internal.WindowsSupport.getConsoleMode(WindowsSupport.java:50)
    at Test$.delayedEndpoint$Test$1(Test.scala:5)
    at Test$delayedInit$body.apply(Test.scala:1)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:76)
    at scala.App$$anonfun$main$1.apply(App.scala:76)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
    at scala.App$class.main(App.scala:76)
    at Test$.main(Test.scala:1)
    at Test.main(Test.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    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)

我尝试了什么并且它不起作用:

  • 互联网上的一些线程提到它可能是由于缺少VC2008运行时引起的,所以我确保我将它同时用于x64和x86。
  • 从scala / lib / jline-2.12.1.jar中提取jansi.dll并将其放入我的工作目录(java.library.path中包含“。”)。
  • 从新的MSys2主目录开始。
  • 从cmd.exe运行bash --login -i(运行scala时出现相同的错误)
  • 尝试32位和64位JRE

还有一件事:问题不影响sbt;例如,运行“sbt console”为我提供了一个可用的Scala命令行,尽管版本为2.10.4。

1 个答案:

答案 0 :(得分:1)

问题是由scala目录中的scala/bin shell脚本与同一目录中的scala.bat之间的名称冲突引起的。 Msys2运行shell脚本,而cmd.exe运行批处理文件。显然,shell脚本不适合Msys2,这会导致我目睹的错误。从MSys2发出cmd //c scala.bat会产生一个功能性Scala命令行。

编辑scala shell脚本以支持MSys2也是微不足道的:https://gist.github.com/kirillkh/a9ba2e00ef2e901f13bf

我在GitHub上打开了一个带有此更改的请求:https://github.com/scala/scala/pull/4674