8

当我通过右键单击“调试”在 IntelliJ 中运行我的 sbt 项目时,我收到此错误消息。

/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 运行它时sbt run,它工作正常。sbt compile也可以工作文件。如何解决此问题,以便我的项目作为应用程序运行?

IntelliJ NoClassDefFoundError

* 解决方案 *

手动添加scala-reflect-2.11.8.jar

jar 文件

4

6 回答 6

11

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

  • 去运行配置
  • 选中包含具有“已提供”范围的依赖项框
于 2018-05-17T17:18:59.410 回答
7

请尝试运行

sbt package

首先从命令行。然后让我们知道这是否能解决问题。

更新仔细看。这是由于scala-reflect.jar没有在 intellij 中获取。你build.sbt

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

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

于 2016-05-29T06:02:57.627 回答
2

如果您使用的是 Mac,您能否检查问题是否与此有关:JavaLaunchHelper 类在 ... libinstrument.dylib 中都实现了。将使用两者之一。哪个是未定义的

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

在此处输入图像描述

于 2018-01-05T13:59:08.870 回答
1

在此处输入图像描述

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

于 2018-07-13T08:54:52.243 回答
0

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

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

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

于 2016-07-20T15:49:50.423 回答
-1

我认为这是SBT、依赖项、类路径和编辑器的副本。我通过从 github 添加这个插件解决了这个问题

于 2017-05-16T16:27:16.527 回答