我在R中使用rscala软件包调用预编译的Scala代码时遇到了麻烦。
我有一个运行在版本2.11.12
上的Scala项目。我用sbt-assembly构建了一个胖子罐,并通过rscala::scala("path-to-jar.jar")
但是,每当我尝试从软件包中运行任何函数/方法/任何内容时,都会收到以下错误消息:
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOps;
at myPackage.myClass$.myMethod(myClass.scala:116)
at $line6.$read$$iw$$iw$$iw$$iw$.$anonfun$res0$1(<console>:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.ddahl.rscala.server.Server.$anonfun$invoke$3(Server.scala:305)
at org.ddahl.rscala.server.Server.wrap(Server.scala:47)
at org.ddahl.rscala.server.Server.invoke(Server.scala:305)
at org.ddahl.rscala.server.Server.run(Server.scala:400)
at org.ddahl.rscala.server.Main$.delayedEndpoint$org$ddahl$rscala$server$Main$1(Main.scala:105)
at org.ddahl.rscala.server.Main$delayedInit$body.apply(Main.scala:11)
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1$adapted(App.scala:80)
at scala.collection.immutable.List.foreach(List.scala:392)
at scala.App.main(App.scala:80)
at scala.App.main$(App.scala:78)
at org.ddahl.rscala.server.Main$.main(Main.scala:11)
at org.ddahl.rscala.server.Main.main(Main.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at scala.reflect.internal.util.ScalaClassLoader.$anonfun$run$2(ScalaClassLoader.scala:106)
at scala.reflect.internal.util.ScalaClassLoader.asContext(ScalaClassLoader.scala:41)
at scala.reflect.internal.util.ScalaClassLoader.asContext$(ScalaClassLoader.scala:37)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:132)
at scala.reflect.internal.util.ScalaClassLoader.run(ScalaClassLoader.scala:106)
at scala.reflect.internal.util.ScalaClassLoader.run$(ScalaClassLoader.scala:98)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:132)
at scala.tools.nsc.CommonRunner.run(ObjectRunner.scala:28)
at scala.tools.nsc.CommonRunner.run$(ObjectRunner.scala:27)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45)
at scala.tools.nsc.CommonRunner.runAndCatch(ObjectRunner.scala:35)
at scala.tools.nsc.CommonRunner.runAndCatch$(ObjectRunner.scala:34)
at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:73)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:92)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:103)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:108)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Error in pop(details, transcompileInfo, envir) : Invocation error.
它确实允许我导入其类和对象,因此它似乎确实在类路径中,仅此而已。
我的build.sbt包中包含crossScalaVersions := Seq("2.11.12", "2.12.7", "2.13.0-M5")
。
有什么想法吗?似乎是scala版本错误,因为运行rscala::scalaConfig()
向我显示它正在使用scalaFullVersion 2.12.8
,但是我似乎无法选择scala安装,因此我不能真正期望这是问题所在
编辑:
在Jasper-M的建议之后,我设置了环境变量RSCALA_SCALA_MAJORVERSION=2.11
,并使用rscala::scalaConfig(download='scala')
重新执行了配置。现在它以scalaMajorVersion
的形式返回2.11
。
现在,当我使用rscala::scala()
创建scala桥的实例时,它将返回一条消息(不是错误),说明:
cat: /release: No such file or directory
如果我运行println()
,则编译不会有任何问题。但是,如果我使用自己的预编译胖JAR实例化scala桥并执行任何操作(例如println
),它将返回以下错误:
error: error while loading package, class file '$HOME/.rscala/scala/lib/scala-library.jar(scala/reflect/package.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
error: error while loading package, class file '$HOME/.rscala/scala/lib/scala-library.jar(scala/package.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
error: error while loading package, class file '$HOME/.rscala/scala/lib/scala-library.jar(scala/reflect/package.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
error: error while loading package, class file '$HOME/.rscala/scala/lib/scala-library.jar(scala/package.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
error: error while loading Predef, class file '$HOME/.rscala/scala/lib/scala-library.jar(scala/Predef.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
我真的很笨。有什么想法吗?
答案 0 :(得分:5)
这绝对是Scala版本错误。
我最好的猜测是您必须设置环境变量RSCALA_SCALA_MAJORVERSION=2.11
。例如。通过致电
Sys.setenv(RSCALA_SCALA_MAJORVERSION = "2.11")
然后运行
rscala::scalaConfig(download = "scala")