【问题标题】:IntelliJ IDEA 13 Scala Plugin & Eclipse Kepler Compilation ErrorIntelliJ IDEA 13 Scala 插件和 Eclipse Kepler 编译错误
【发布时间】:2013-12-21 06:33:20
【问题描述】:

代码:

import com.google.common.base.Joiner
import scala.collection.JavaConverters._

object MainJ extends App {
   val fantasyGeneres = Array("Space Opera", "Horror", "Magic realism", "Religion")
   val joined = Joiner.on(',').join(fantasyGeneres.toIterable.asJava)
println(joined)
}

IntelliJ IDEA 错误:

scala: error while loading Joiner, class file 'C:\guava-    15.0.jar(com/google/common/base/Joiner.class)' is broken
(class java.lang.RuntimeException/bad constant pool tag 9 at byte 10)

Scala 插件版本:

Scala -> 0.26.318
Version: 0.26.318
Date: 2013-12-04 10:46
Since: 133.124
Until: 134.0
Size: 25346.32 Kb

Eclipse 错误:

Description Resource    Path    Location    Type
error while loading Joiner, class file 'C:\guava-15.0.jar(com/google/common/base/Joiner.class)' is broken (class java.lang.RuntimeException/bad constant pool tag 9 at byte 10) Scala       Unknown Scala Problem

请看上面的图片,我用 Guava 库和 scala 语言编写了一个程序

何时我使用 Eclipse IDE with Scala Plugin 和 IntelliJ IDEA with Scala Plugin 上面的错误显示我无法编译它

谁能帮帮我?

【问题讨论】:

  • 您使用的是尚未正式发布的JDK8,您确定这不是与那个+Scala不兼容的问题吗?
  • 确保你已经升级了scala插件。 scala 插件未与 IDEA 捆绑,因此从 IDEA 12 升级到 13 后必须手动更新。
  • 我更新了我的帖子,请查看新信息
  • 其他 Guava 类是否正常工作?如果你包含 Apache Commons 而不是 Guava 并使用它的 StringJoiner 会发生什么?

标签: java eclipse scala intellij-idea guava


【解决方案1】:

这不是 IDE 的错误。事实上,这就是 Scala 编译器的工作方式。与 Java 编译器不同,Scala 编译器需要代码直接使用的所有库的所有注解。 Guava 依赖于 JSR-305 注释,因此您必须在构建中包含相应的 JAR。

请参阅herehere 了解更多信息。这是 Maven 依赖描述符,复制自 here:

<dependency>
    <groupId>com.google.code.findbugs</groupId>
    <artifactId>jsr305</artifactId>
    <version>2.0.2</version>
</dependency>

【讨论】:

  • 谢谢,现在可以工作了:D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-25
  • 1970-01-01
  • 2013-01-05
  • 1970-01-01
  • 2021-11-29
  • 1970-01-01
  • 2011-11-12
相关资源
最近更新 更多