【问题标题】:java.lang.NoClassDefFoundError: scala/reflect/api/TypeCreatorjava.lang.NoClassDefFoundError: scala/reflect/api/TypeCreator
【发布时间】:2016-09-27 02:04:06
【问题描述】:

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

/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 作为应用程序运行?

* 解决方案 *

手动添加scala-reflect-2.11.8.jar

【问题讨论】:

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


    【解决方案1】:

    请尝试运行

    sbt package
    

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

    更新仔细查看。这是因为 scala-reflect.jar 没有在 intellij 中被接收。你确实拥有build.sbt

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

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

    【讨论】:

    • @MichaelLafayette 感谢反馈:我更新了答案。
    • @MichaelLafayette 我 did - 这就是上面显示的行的位置。我的更新答案甚至说:请重新阅读。
    • @javaba - 天哪。
    • @javaba - 谢谢。旁注:你如何回答问题?我基本上只看到主页——没有一个问题与我的兴趣有关,然后我点击“”。当有人提出与 Scala/Spark 相关的问题时,您是否设置了通知您?
    • 好的,这里是:点击“问题”。然后在右侧有一个“最喜欢的标签”列表。您可以点击“编辑”选择您喜欢的。
    【解决方案2】:

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

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

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

          【解决方案5】:

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

          • 去运行配置
          • 选中包含具有“已提供”范围的依赖项复选框

          【讨论】:

            【解决方案6】:

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

            【讨论】:

            • 嗯,好的 - 这可能会有所帮助,而不是要求每个 scala 模块都添加
            猜你喜欢
            • 2013-08-08
            • 1970-01-01
            • 1970-01-01
            • 2019-08-05
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-07-18
            • 2016-03-24
            相关资源
            最近更新 更多