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

10,661

Solution 1

Please try running

sbt package

from the command line first. Then let us know if that fixes the issue.

Update Looked more closely. This is due to scala-reflect.jar not being picked up within intellij. You do have it the build.sbt:

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

Please add that dependency manually to the intellij project. Why IJ did not pick it up is uncertain so this is basically a hack. But with intellij fixes like this are unfortunately sometimes required.

Solution 2

For me the following worked (without including scala-reflect to classpath):

  • Go to run configurations
  • Check the box Include dependencies with "Provided" scope

Solution 3

If you are on a Mac, could you check if the issue is related to this : Class JavaLaunchHelper is implemented in both ... libinstrument.dylib. One of the two will be used. Which one is undefined

Also, I tried removing the Scala SDK from the Global libraries and added it again. Worked great !!

enter image description here

Solution 4

enter image description here

I solved this problem by adding scala-reflect.jar to Standard library.

Share:
10,661
Michael Lafayette
Author by

Michael Lafayette

LinkedIn: https://www.linkedin.com/in/john-reed-154587120 Blog: https://johnreedprogrammer.wordpress.com/ YouTube: https://www.youtube.com/playlist?list=PLXcr3tdUCbQb6zjN6kw4s20joId2jygUe

Updated on June 04, 2022

Comments

  • Michael Lafayette
    Michael Lafayette almost 2 years

    I'm getting this error message when I run my sbt project in IntelliJ by right clicking "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
    

    I only get this error when I run from IntelliJ. When I run it from SBT with sbt run, it works fine. sbt compile works file too. How do I fix this so my project runs as an Application?

    IntelliJ NoClassDefFoundError

    * Solution *

    Manually add scala-reflect-2.11.8.jar

    jar file

  • WestCoastProjects
    WestCoastProjects almost 8 years
    @MichaelLafayette thx for the feedback: I updated the answer.
  • WestCoastProjects
    WestCoastProjects almost 8 years
    @MichaelLafayette I did - that is from where the line shown above is.. my updatd answer even says as much: please re-read it.
  • Michael Lafayette
    Michael Lafayette almost 8 years
    @javaba - Oh my god.
  • Michael Lafayette
    Michael Lafayette almost 8 years
    @javaba - Thanks. Side note: How do you go about answering questions? I basically just see the homepage - none of the questions are related to my interests, and then I click "Ask Question". Do you set SO up to notify you when someone asks a question related to Scala/Spark?
  • WestCoastProjects
    WestCoastProjects almost 8 years
    You can choose which tags. Hold a moment I'll go find out the details.
  • WestCoastProjects
    WestCoastProjects almost 8 years
    Ok here it is: click on "Questions". then on the right side there is a list of "Favorite Tags". You can click on "Edit" to choose the ones you prefer.
  • WestCoastProjects
    WestCoastProjects over 4 years
    ah ok - that can be helpful instead of requiring adding by every scala module