When right-click running a test class, Eclipse failed with
Caused by: java.lang.NoClassDefFoundError: scala/Product$class
at org.scalatest.time.Days$.<init>(Units.scala:291)
at org.scalatest.time.Days$.<clinit>(Units.scala)
at org.scalatest.time.Span$.<init>(Span.scala:585)
at org.scalatest.time.Span$.<clinit>(Span.scala)
at org.scalatest.tools.Runner$.<init>(Runner.scala:779)
at org.scalatest.tools.Runner$.<clinit>(Runner.scala)
at org.scalatest.tools.Runner.main(Runner.scala)
... 6 more
Caused by: java.lang.ClassNotFoundException: scala.Product$class
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more
Yet it ran in the command line with sbt test. The libraries have been updated as described in java.lang.NoClassDefFoundError: scala/Product$class.
This happened with the latest Scala IDE (4.7.0-vfinal-2017-09-29T14:34:02Z-Typesafe) with the patmat project from Coursera's scala course.
What is the cause and how can it be fixed?
Requested info
The Java Build Path is
You have a combination of _2.11 libraries and 2.12.3 Scala library, this won't work. It looks like the _2.11 dependendencies come from SBT (judging from the paths).
You need to either change Scala IDE's Scala version (setting correct scala version on scala ide explains how) or set scalaVersion := "2.12.3" in the SBT project and rerun sbt eclipse.
Please use the Scala library version 2.11 as the other Scala based dependencies like scala-xml and scalatest are based on Scala library version 2.11
Related
i have a kafkaflink job which works in intellij, on packaging with sbt i get the below message
Caused by: java.lang.ClassNotFoundException:
org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer
Thanks for having a look at it
You most certainly have Kafka as provided dependency or you are not creating the fat-jar.
You need to use a plugin depending on the build tool You are using for sbt it can be sbt assembly, for maven it can be maven-shade-plugin. And then You need to have flink-kafka-connector in compile scope.
I'm using intellij community 2018.3 with scala 2.12.
I try to generate scaladoc of my project (a library) but intellij print me this error:
Exception in thread "main" java.lang.NoSuchMethodError: scala.reflect.io.FileZipArchive.allDirsByDottedName()Lscala/collection/Map;
at scala.tools.nsc.classpath.ZipArchiveFileLookup.findDirEntry(ZipArchiveFileLookup.scala:71)
at scala.tools.nsc.classpath.ZipArchiveFileLookup.list(ZipArchiveFileLookup.scala:53)
at scala.tools.nsc.classpath.ZipArchiveFileLookup.list$(ZipArchiveFileLookup.scala:52)
at scala.tools.nsc.classpath.ZipAndJarClassPathFactory$ZipArchiveClassPath.list(ZipAndJarFileLookupFactory.scala:42)
at scala.tools.nsc.classpath.AggregateClassPath.$anonfun$list$1(AggregateClassPath.scala:76)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.Iterator.foreach(Iterator.scala:944)
at scala.collection.Iterator.foreach$(Iterator.scala:944)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1432)
at scala.collection.IterableLike.foreach(IterableLike.scala:71)
at scala.collection.IterableLike.foreach$(IterableLike.scala:70)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike.map(TraversableLike.scala:234)
at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at scala.tools.nsc.classpath.AggregateClassPath.list(AggregateClassPath.scala:74)
at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader.doComplete(SymbolLoaders.scala:271)
at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:220)
at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1535)
at scala.reflect.internal.Mirrors$RootsBase.init(Mirrors.scala:225)
at scala.tools.nsc.Global.rootMirror$lzycompute(Global.scala:65)
at scala.tools.nsc.Global.rootMirror(Global.scala:63)
at scala.tools.nsc.Global.rootMirror(Global.scala:36)
at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(Definitions.scala:267)
at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(Definitions.scala:267)
at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1423)
at scala.tools.nsc.Global$Run.<init>(Global.scala:1179)
at scala.tools.nsc.doc.DocFactory.makeUniverse(DocFactory.scala:44)
at scala.tools.nsc.doc.DocFactory.generate$1(DocFactory.scala:124)
at scala.tools.nsc.doc.DocFactory.document(DocFactory.scala:131)
at scala.tools.nsc.ScalaDoc.process(ScalaDoc.scala:41)
at scala.tools.nsc.ScalaDoc$.main(ScalaDoc.scala:92)
at scala.tools.nsc.ScalaDoc.main(ScalaDoc.scala)
Process finished with exit code 1
IDE is update. What can I do?
It could be the following:
Also you are on scala 2.12, scala reflect seems to be on 2.11 or other version.
Add a dependency to scala reflect to your project:
https://mvnrepository.com/artifact/org.scala-lang/scala-reflect/2.12.8
Running Specs2 in IntelliJ fails. Running the same tests manually via an SBT task works just fine without any problems.
Message: "Test framework quit unexpectedly"
IntelliJ: v.15.0.5 or 2016.2 EAP (build #IC-162.426.1)
Platform: Scala 2.11.7, SBT 0.13.8, Specs2 2.4.17, Play! 2.3.10
This is a common error response, but it looks like the root cause is different for a lot of other people. I have troubleshoot this issue before and corrected it by adding the following to build.sbt:
fork in Test := false
parallelExecution in Test := false
Now the tests are failing again. I have looked through the revision history of our build.sbt file but I do not notice anything significant that would instigate such a regression and I have no clues.
Upon step-debugging the crash I have found the following root cause:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.specs2.reflect.Classes$class.createInstanceFor(Classes.scala:154)
at org.specs2.reflect.Classes$.createInstanceFor(Classes.scala:207)
at org.specs2.reflect.Classes$$anonfun$createInstanceOfEither$1.apply(Classes.scala:145)
at org.specs2.reflect.Classes$$anonfun$createInstanceOfEither$1.apply(Classes.scala:145)
at scala.Option.map(Option.scala:146)
at org.specs2.reflect.Classes$class.createInstanceOfEither(Classes.scala:145)
at org.specs2.reflect.Classes$.createInstanceOfEither(Classes.scala:207)
at org.specs2.reflect.Classes$class.org$specs2$reflect$Classes$$createInstanceForConstructor(Classes.scala:118)
at org.specs2.reflect.Classes$$anonfun$4.apply(Classes.scala:98)
at org.specs2.reflect.Classes$$anonfun$4.apply(Classes.scala:98)
at scala.collection.immutable.List.map(List.scala:273)
at org.specs2.reflect.Classes$class.tryToCreateObjectEither(Classes.scala:98)
at org.specs2.reflect.Classes$.tryToCreateObjectEither(Classes.scala:207)
at org.specs2.reflect.Classes$class.tryToCreateObject(Classes.scala:70)
at org.specs2.reflect.Classes$.tryToCreateObject(Classes.scala:207)
at org.specs2.specification.SpecificationStructure$.createSpecificationFromClassOrObject(BaseSpecification.scala:126)
at org.specs2.specification.SpecificationStructure$.createSpecificationOption(BaseSpecification.scala:107)
at org.specs2.specification.SpecificationStructure$.createSpecification(BaseSpecification.scala:95)
at org.specs2.runner.ClassRunner.createSpecification(ClassRunner.scala:60)
at org.specs2.runner.ClassRunner.start(ClassRunner.scala:31)
at org.specs2.runner.NotifierRunner.start(NotifierRunner.scala:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.runSpecs2_old(JavaSpecs2Runner.java:133)
at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.runSingleTest(JavaSpecs2Runner.java:204)
at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.main(JavaSpecs2Runner.java:85)
Caused by: java.lang.IncompatibleClassChangeError: Found class scalaz.Tree, but interface was expected
at org.specs2.mutable.SideEffectingCreationPaths$class.$init$(FragmentsBuilder.scala:245)
at org.specs2.mutable.Specification.<init>(Specification.scala:12)
at controllers.VerificationApiSpec.<init>(VerificationApiSpec.scala:26)
... 32 more
scalaz.Tree is a transitive dependency of many other dependencies in my project that request versions including 7.1.1, 7.1.2, 7.1.3, 7.0.6 of scalaz. It's interesting to note that in 7.0.x scalaz.Tree is a trait (interface in Java vernacular) but an abstract class in 7.1.x, so this may constitute the root cause.
Is it possible to resolve this issue given the transitive dependency conflicts with scalaz 7.1.x and 7.0.x which are evidentially incompatible?
Specs2 2.4.17 uses Scalaz 7.1.0. Some other dependency in your build is probably dragging a Scalaz 7.2.x dependency. I suggest that you update your specs2 version to 3.8.4 which will bring a more recent version of Scalaz in scope.
I am trying to run a play framework(2.1) application which is written in Scala but getting some error.
I need to use Play framework 2.1 only.
As per build.sbt file, I am using Scala 2.11.7.
sbt.version=0.13.8 is in project/build.properties.
I have installed Play 2.1.0 and changed my directory to application's root directory and then executed play command.
I got following error:
java.lang.NoClassDefFoundError: scala/StringContext
at sbt.CommandStrings$.<init>(CommandStrings.scala:83)
at sbt.CommandStrings$.<clinit>(CommandStrings.scala)
at sbt.BuiltinCommands$.defaults(Main.scala:202)
at sbt.xMain.run(Main.scala:29)
at xsbt.boot.Launch$.run(Launch.scala:55)
at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:45)
at xsbt.boot.Launch$.launch(Launch.scala:69)
at xsbt.boot.Launch$.apply(Launch.scala:16)
at xsbt.boot.Boot$.runImpl(Boot.scala:31)
at xsbt.boot.Boot$.main(Boot.scala:20)
at xsbt.boot.Boot.main(Boot.scala)
Caused by: java.lang.ClassNotFoundException: scala.StringContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 11 more
Error during sbt exeenter code herecution: java.lang.NoClassDefFoundError: scala/StringContext
Can someone please tell me what's wrong here?
I am completely new to scala and I just need to run this app at earliest.
I am using 64-bit Cent OS 7(in case someone wants to know about OS).
The easiest way to fix that is to use an older version of SBT. Play 2.1.5 uses 0.12.2 by default, so you can change the file project/build.properties inside your project and use that version:
sbt.version=0.12.2
You can later try newer versions of SBT if you need.
sbt.version=0.12.2 wont work with JDK8 so you might need to downgrade Java.
I used this sbt version and got the following error
eror: error while loading CharSequence, class file '/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar(java/lang/CharSequence.class)' is broken for sbt 0.12.2
I'm unable to figure out what is wrong with this program? I'm using an older verison of scala (2.7) because its compatible with certain libraries i'm using
Here is a simple program i'm attempting to run.
The program runs fine using scalac and scala commands.
However on IntelliJ 14+ -> when i create a new project -> select the compiler (scala 2.7) and try to run the above program i get this error below
object SimpleClass {
def main(args: Array[String]) {
println("This is a simple Class")
}
}
Error output.
Why does intelliJ throw the ClassNotFoundException? I've saved the program as SimpleClass.scala
/usr/lib/jvm/java-7-openjdk-i386/bin/java -Didea.launcher.port=7532 -Didea.launcher.bin.path=/home/tejesh/Downloads/idea-IC-141.1532.4/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-7-openjdk-i386/jre/lib/javazic.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/management-agent.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/resources.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/rhino.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/charsets.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/jce.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/jsse.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/rt.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/compilefontconfig.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/java-atk-wrapper.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/icedtea-sound.jar:/usr/local/share/scala-2.7.3/lib/scala-swing.jar:/usr/local/share/scala-2.7.3/lib/scala-library.jar:/home/tejesh/Downloads/idea-IC-141.1532.4/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain SimpleClass
Exception in thread "main" java.lang.ClassNotFoundException: SimpleClass
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)
I've added the folder containing the SimpleClass as under sources
This is the full program here
Recent Scala for IntelliJ IDEA is based on sbt. Apparently Scala 2.7.3 is not supported any longer in this configuration. If you set up a project, IntelliJ will offer you (when you select "Download" for the SDK) no version older than Scala 2.8.0. If you manually select 2.7.3, the following happens when you try to compile:
Error:scalac: Error: org.jetbrains.jps.incremental.scala.remote.ServerException
Error compiling sbt component 'compiler-interface-2.7.3.final-52.0'
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:145)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:142)
at sbt.IO$.withTemporaryDirectory(IO.scala:285)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1.apply(AnalyzingCompiler.scala:142)
at
...
The next step is Scala 2.8.2, for which you get:
Error:scalac: Parameter '-nobootcp' is not recognised by Scalac.
It seems the oldest Scala that works with the current IntelliJ is 2.9.0. (You have to use Java 7 and not Java 8 for this!)
The solution would be to downgrade IntelliJ IDEA to an old version that still supports Scala 2.7.3 (perhaps IDEA 11?), or to simply set up the project with Scala 2.9.3, but compile instead manually (or using sbt from the terminal) against 2.7.3.
If you have the source to the library that requires 2.7.3, perhaps the best option is to try to compile the library with contemporary versions of Scala (at least 2.9.0).