java.lang.NoClassDefFoundError:scala / reflect / api / TypeCreator

时间:2016-05-29 01:43:35

标签: scala intellij-idea reflection classnotfoundexception intellij-scala

当我在IntelliJ中运行my sbt project时,右键单击" Debug"

,我收到此错误消息
/home/johnreed/Applications/jdk1.8.0_73/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:34395,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath /home/johnreed/Applications/jdk1.8.0_73/jre/lib/charsets.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/deploy.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/cldrdata.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/dnsns.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/jaccess.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/jfxrt.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/localedata.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/nashorn.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/sunec.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/sunjce_provider.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/sunpkcs11.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/zipfs.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/javaws.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/jce.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/jfr.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/jfxswt.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/jsse.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/management-agent.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/plugin.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/resources.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/rt.jar:/home/johnreed/sbtProjects/UnderstandingScala/target/scala-2.11/classes:/home/johnreed/.ivy2/cache/com.chuusai/shapeless_2.11/bundles/shapeless_2.11-2.3.1.jar:/home/johnreed/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.8.jar:/home/johnreed/.ivy2/cache/com.google.code.findbugs/jsr305/jars/jsr305-2.0.1.jar:/home/johnreed/.ivy2/cache/com.google.guava/guava/bundles/guava-16.0.1.jar:/home/johnreed/.ivy2/cache/com.twitter/jsr166e/jars/jsr166e-1.0.0.jar:/home/johnreed/.ivy2/cache/com.twitter/util-collection_2.11/jars/util-collection_2.11-6.34.0.jar:/home/johnreed/.ivy2/cache/com.twitter/util-core_2.11/jars/util-core_2.11-6.34.0.jar:/home/johnreed/.ivy2/cache/com.twitter/util-function_2.11/jars/util-function_2.11-6.34.0.jar:/home/johnreed/.ivy2/cache/commons-collections/commons-collections/jars/commons-collections-3.2.2.jar:/home/johnreed/.ivy2/cache/javax.inject/javax.inject/jars/javax.inject-1.jar:/home/johnreed/.ivy2/cache/org.scala-lang.modules/scala-parser-combinators_2.11/bundles/scala-parser-combinators_2.11-1.0.4.jar:/home/johnreed/.ivy2/cache/org.typelevel/macro-compat_2.11/jars/macro-compat_2.11-1.1.1.jar:/home/johnreed/.ivy2/cache/scala.trace/scala-trace-debug_2.11/jars/scala-trace-debug_2.11-2.2.14.jar:/home/johnreed/Applications/idea-IC-145.258.11/lib/idea_rt.jar pkg.Main
Connected to the target VM, address: '127.0.0.1:34395', transport: 'socket'
Disconnected from the target VM, address: '127.0.0.1:34395', transport: 'socket'
Exception in thread "main" java.lang.NoClassDefFoundError: scala/reflect/api/TypeCreator
    at pkg.Main.main(Main.scala)
Caused by: java.lang.ClassNotFoundException: scala.reflect.api.TypeCreator
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

Process finished with exit code 1

从IntelliJ运行时,我只收到此错误。当我使用sbt run从SBT运行它时,它工作正常。 sbt compile也可以处理文件。如何解决此问题,以便my project作为应用程序运行?

IntelliJ NoClassDefFoundError

*解决方案*

手动添加 scala-reflect-2.11.8.jar

jar file

6 个答案:

答案 0 :(得分:4)

请尝试运行

new Date().addMinutes(1)
new Date().add(1).minute()
new Date().add({ minutes: 1 });
首先从命令行

。然后告诉我们是否可以解决问题。

更新仔细观察。这是因为sbt package 未在intellij中被选中。你拥有scala-reflect.jar

build.sbt

请手动将该依赖项添加到intellij项目中。为什么IJ没有拿起它是不确定的所以这基本上是一个黑客。但是对于intellij这样的修复很遗憾有时需要。

答案 1 :(得分:3)

对我来说,以下工作(不包括scala-reflect到classpath):

  • 转到运行配置
  • 选中包含依赖关系框"提供"范围

答案 2 :(得分:2)

如果您使用的是Mac,是否可以检查问题是否与此相关:Class JavaLaunchHelper is implemented in both ... libinstrument.dylib. One of the two will be used. Which one is undefined

此外,我尝试从全局库中删除Scala SDK并再次添加它。工作得很棒!!

enter image description here

答案 3 :(得分:0)

这个问题昨天毁了我的一天。今天我被intellij提示下载v2016.2(我在v2016.1上),这个问题就消失了。我从build.sbt中删除了以下行:

"org.scala-lang" % "scala-reflect" % version % "provided"

并且能够成功构建和运行项目。

答案 4 :(得分:0)

enter image description here

我通过将scala-reflect.jar添加到标准库中解决了这个问题。

答案 5 :(得分:-1)

我认为这是SBT, dependencies, classpath and editors的副本。我通过添加this plugin from github

解决了这个问题