简体   繁体   English

IntelliJ IDEA 13 Scala插件和Eclipse Kepler编译错误

[英]IntelliJ IDEA 13 Scala Plugin & Eclipse Kepler Compilation Error

IntelliJ IDEA日食

Code : 代码:

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 Error : 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 Plugin Version : 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 Error : 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

please see above images, I wrote a program with Guava library and scala language 请看上面的图片,我用Guava库和scala语言编写了一个程序

WHEN I use Eclipse IDE with Scala Plugin & IntelliJ IDEA with Scala Plugin above error shows and I cant compile it 我使用Eclipse IDE与Scala插件和IntelliJ IDEA与Scala插件上面的错误显示,我无法编译它

Can anyone help me ? 谁能帮我 ?

This is not a fault of IDE. 这不是IDE的错。 In fact it is how Scala compiler works. 实际上它是Scala编译器的工作方式。 Unlike Java compiler, Scala compiler needs all the annotations for all libraries directly used by your code. 与Java编译器不同,Scala编译器需要代码直接使用的所有库的所有注释。 Guava depends on JSR-305 annotations, so you must include corresponding JAR into your build. Guava依赖于JSR-305注释,因此您必须在构建中包含相应的JAR。

See here and here for more information. 有关更多信息,请参见此处此处 This is Maven dependency descriptor, copied from here : 这是Maven依赖描述符,从这里复制:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM