java.lang.NoClassDefFoundError: scala/reflect/api/TypeCreator
Asked Answered
R

6

10

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

Runagate answered 29/5, 2016 at 1:43 Comment(0)
M
7

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.

Monika answered 29/5, 2016 at 6:2 Comment(6)
@MichaelLafayette thx for the feedback: I updated the answer.Monika
@MichaelLafayette I did - that is from where the line shown above is.. my updatd answer even says as much: please re-read it.Monika
@javaba - Oh my god.Runagate
@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?Runagate
You can choose which tags. Hold a moment I'll go find out the details.Monika
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.Monika
H
14

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

  • Go to run configurations
  • Check the box Include dependencies with "Provided" scope
Hopping answered 17/5, 2018 at 17:18 Comment(0)
M
7

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.

Monika answered 29/5, 2016 at 6:2 Comment(6)
@MichaelLafayette thx for the feedback: I updated the answer.Monika
@MichaelLafayette I did - that is from where the line shown above is.. my updatd answer even says as much: please re-read it.Monika
@javaba - Oh my god.Runagate
@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?Runagate
You can choose which tags. Hold a moment I'll go find out the details.Monika
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.Monika
T
2

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

Tympanic answered 5/1, 2018 at 13:59 Comment(0)
A
1

enter image description here

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

Actinolite answered 13/7, 2018 at 8:54 Comment(1)
ah ok - that can be helpful instead of requiring adding by every scala moduleMonika
A
0

This problem was ruining my day yesterday. Today I was prompted by intellij to download v2016.2 ( I was on v2016.1) and this problem went away. I have removed the following line from my build.sbt:

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

And was able to build and run the project successfully.

Amyotonia answered 20/7, 2016 at 15:49 Comment(0)
S
-1

I think this is a duplicate of SBT, dependencies, classpath and editors. I solved it by adding this plugin from github

Standice answered 16/5, 2017 at 16:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.