java.lang.NoClassDefFoundError: scala/Product$class
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/42498035/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.NoClassDefFoundError: scala/Product$class
提问by Amogh Huilgol
I am new to scala and I am trying out few sample codes for testing. However I am facing some issues when I run the test code. When I run the test, I am getting an error
我是 Scala 的新手,我正在尝试一些示例代码进行测试。但是,当我运行测试代码时,我遇到了一些问题。当我运行测试时,我收到一个错误
[trace] Stack trace suppressed: run last test:executeTests for the full output.
[error] (test:executeTests) java.lang.NoClassDefFoundError: scala/Product$class
[error] Total time: 3 s, completed Feb 27, 2017 6:57:15 PM
My code is as follows
我的代码如下
FilterChecks.scala
FilterChecks.scala
    class filterChecks extends FlatSpec {
  "Filter checker passed a filename which is present in directory" should "return file name" in {
    val matchingFileName = new FileObject("match")
    val listOfFiles = List(new FileObject("random"), matchingFileName)
    val matchedFiles = new FilterChecker("match").findMatchedFiles(listOfFiles)
    assert(matchedFiles == List(matchingFileName))
  }
}
FilterChecker Class
FilterChecker 类
class FilterChecker(filter : String) {
  def matches(content : String) = content.contains(filter);
  def findMatchedFiles(fileObjects : List[FileObject]) = {
    for(fileObject <- fileObjects if(matches(fileObject.name)))
      yield fileObject
  }
}
FileObject
文件对象
class FileObject(val name: String) {
}
The build file is as follows:
构建文件如下:
name := "testScalaProject"
version := "1.0"
scalaVersion := "2.12.1"
// https://mvnrepository.com/artifact/org.scala-js/scalajs-test-interface_2.12
libraryDependencies ++= Seq("org.scala-js" % "scalajs-test-interface_2.12" % "0.6.14",
  "org.scalatest" % "scalatest_2.11" % "2.2.5",
  "com.novocode" % "junit-interface" % "0.11",
  "org.scala-lang" % "scala-library" % "2.12.1")
Could someone help me out in finding the issue . Thanks in advance
有人可以帮我找出问题所在。提前致谢
回答by rogue-one
your sbt build file is not right. your scala version is 2.12.x but you are using libraries compiled in scala version 2.11. use the sbt settings shown below
您的 sbt 构建文件不正确。您的 Scala 版本是 2.12.x,但您使用的是在 2.11 版 Scala 中编译的库。使用下面显示的 sbt 设置
note: I changed the version of scalatest as 2.x versions are no longer supported for 2.12 version of scala
注意:我更改了 scalatest 的版本,因为 2.12 版本的 scala 不再支持 2.x 版本
scalaVersion := "2.12.1"
libraryDependencies ++= Seq(
  "org.scala-js" %% "scalajs-test-interface" % "0.6.14",
  "org.scalatest" %% "scalatest" % "3.0.1", //version changed as these the only versions supported by 2.12
  "com.novocode" % "junit-interface" % "0.11",
  "org.scala-lang" % "scala-library" % scalaVersion.value
)
remember to do reload, cleanand compilein your sbt console to start clean compile 
记得这样做reload,clean并compile在您的 sbt 控制台中开始干净编译

