1
votes

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

java build path

2
Looks like an eclipse project configuration issue, I am not much familiar with eclipse. Let me know if you still getting errors with this project using IntelliJ IDEA.lprakashv
@LalitPrakash: works like a charm in IntelliJ IDEA. Any clue how to fix in Eclipse?serv-inc

2 Answers

3
votes

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.

3
votes

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