编译失败:在 Scala 2.10 下从 Java 8 加载 AnnotatedElement、ConcurrentMap、CharSequence 时出错?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24197836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 06:20:34  来源:igfitidea点击:

Compilation failed: error while loading AnnotatedElement, ConcurrentMap, CharSequence from Java 8 under Scala 2.10?

scalasbt

提问by jnfr

I'm using the following:

我正在使用以下内容:

  • Scala 2.10.4
  • Scalatra 2.2.2
  • sbt 0.13.0
  • java 1.8.0
  • casbah 2.7.2
  • scalatra-sbt 0.3.5
  • 斯卡拉 2.10.4
  • Scalatra 2.2.2
  • sbt 0.13.0
  • 爪哇 1.8.0
  • 卡斯巴 2.7.2
  • scalatra-sbt 0.3.5

I'm frequently running into this error:

我经常遇到这个错误:

21:32:00.836 [qtp1687101938-55] ERROR o.fusesource.scalate.TemplateEngine - Compilation failed:
error: error while loading CharSequence, class file '/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar(java/lang/CharSequence.class)' is broken
(class java.lang.RuntimeException/bad constant pool tag 18 at byte 10)
error: error while loading ConcurrentMap, class file '/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar(java/util/concurrent/ConcurrentMap.class)' is broken
(class java.lang.RuntimeException/bad constant pool tag 18 at byte 61)
two errors found
21:38:03.616 [qtp1687101938-56] ERROR o.fusesource.scalate.TemplateEngine - Compilation failed:
error: error while loading AnnotatedElement, class file '/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar(java/lang/reflect/AnnotatedElement.class)' is broken
(class java.lang.RuntimeException/bad constant pool tag 18 at byte 76)
one error found

Currently I'm running into this when simply trying to call a .count()on my MongoDB collection.

目前,当我只是尝试.count()在我的 MongoDB 集合上调用 a 时遇到了这个问题。

Upon Googling, it seems like it may be caused by dependency issues. The thing is, I'm using Scalatra just to serve an API and actually don't require any of the scalate stuff. I commented out all references to it, but I still get this. Could it be a dependency issue between the libraries I'm using?

在谷歌上搜索,它似乎可能是由依赖问题引起的。问题是,我使用 Scalatra 只是为了提供 API,实际上不需要任何 scalate 东西。我注释掉了所有对它的引用,但我仍然得到了这个。这可能是我使用的库之间的依赖问题吗?

回答by bkowalikpl

In my company we had this problem with CharSequence. This is due to Scala 2.10.x does not work with Java 8. This was described in Scalas mailinglist. Switch back to Java 7.

在我的公司,我们遇到了 CharSequence 的这个问题。这是由于斯卡拉2.10.x不与Java 8这项工作在Scalas被描述邮件列表。切换回 Java 7。

回答by José Ricardo

Switching to Scala 2.10.4 solved the problem for me.

切换到 Scala 2.10.4 为我解决了这个问题。

回答by viirya

I have a similar problem on Java 1.8.0 working with Scala 2.10.4 and sbt 0.12.4. But when upgrading to sbt 0.13.7, the problem is solved.

我在使用 Scala 2.10.4 和 sbt 0.12.4 的 Java 1.8.0 上有类似的问题。但是升级到sbt 0.13.7后,问题就解决了。

回答by Edi Bice

I am seeing the same issue with software requiring Scala 2.9.2+ and Java 1.7 running on Scala 2.10.4 and Java 1.8. Changed to Java 7 via sudo update-alternatives --config java

我发现需要 Scala 2.9.2+ 和 Java 1.7 在 Scala 2.10.4 和 Java 1.8 上运行的软件也存在同样的问题。通过 sudo update-alternatives --config java 更改为 Java 7

回答by Panda1667075

I solved this by using:

我通过使用解决了这个问题:

<dependency>
    <groupId>org.scala-lang</groupId>
    <artifactId>scala-library</artifactId>
    <version>2.10.2-RC2</version>
</dependency>

My environment is:

我的环境是:

  • JDK 8
  • Maven
  • Scala
  • JDK 8
  • 马文
  • 斯卡拉

回答by Nagaraj Vittal

I also got the same issue in Ubuntu 14.04 but I solved by removing the scala 2.10 and installing 2.11

我在 Ubuntu 14.04 中也遇到了同样的问题,但我通过删除 scala 2.10 并安装 2.11 解决了

wget www.scala-lang.org/files/archive/scala-2.11.7.deb

 

 

dpkg -i scala-2.11.7.deb

Now try.

现在试试。

回答by Sean Bradley

That was a lot of reconfiguration for me to get it to work, here is my (NOW) working build.sbt using, sbt 0.13.15 and scala 2.10.4 and jdk 1.8.1_131

这对我来说是很多重新配置才能让它工作,这是我(现在)正在使用的 build.sbt,sbt 0.13.15 和 scala 2.10.4 和 jdk 1.8.1_131

name := "ScalaTelemetryManagerApi"
version := "1.0"
scalaVersion := "2.10.4"
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8")

libraryDependencies ++= {
  Seq(
    "io.spray"            %   "spray-can"     % "1.3.1",
    "io.spray"            %   "spray-routing" % "1.3.1",
    "io.spray"            %   "spray-testkit" % "1.3.1",
    "com.typesafe.akka"   %%  "akka-actor"    % "2.3.2",
    "com.typesafe.akka"   %%  "akka-testkit"  % "2.3.2",
    "org.specs2"          %%  "specs2-core"   % "3.6",
    "com.github.seratch"  %%  "awscala"       % "0.5.+",
    "org.scalaz"      %%  "scalaz-core"   % "7.2.14"
  )
}

resolvers += "Scalaz Bintray Repo" at "https://dl.bintray.com/scalaz/releases"

Revolver.settings

retrieveManaged := true

回答by Ali

I had the same problem. However by switching to Java 7 my problem is resolved. So now this configuration works for me:

我有同样的问题。但是,通过切换到 Java 7,我的问题得到了解决。所以现在这个配置对我有用:

sbt 0.13.8
scala 2.11.7
java 7

回答by Murtaza Kanchwala

I hope a stable version of Scala will help you, Try 2.10.x with Java 1.7.x versions for better performance.

我希望 Scala 的稳定版本对您有所帮助,尝试 2.10.x 和 Java 1.7.x 版本以获得更好的性能。

I mean it worked for me also in the same.

我的意思是它也对我有用。