1

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

Community
  • 1
  • 1
serv-inc
  • 35,772
  • 9
  • 166
  • 188
  • 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 Feb 05 '19 at 08:56
  • @LalitPrakash: works like a charm in IntelliJ IDEA. Any clue how to fix in Eclipse? – serv-inc Feb 06 '19 at 08:02

2 Answers2

3

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

lprakashv
  • 1,121
  • 10
  • 19
  • 1
    You found the solution, so you got the bounty. Thank you again. The other answer got accepted because it contains background information that helps other users understand and fix the problem. – serv-inc Feb 06 '19 at 08:44
3

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.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487