gpt4 book ai didi

scala - java.lang.NoClassDefFoundError:scala/Product $ class

转载 作者:行者123 更新时间:2023-12-03 11:51:35 27 4
gpt4 key购买 nike

我是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

我的代码如下

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(filter : String) {

def matches(content : String) = content.contains(filter);

def findMatchedFiles(fileObjects : List[FileObject]) = {
for(fileObject <- fileObjects if(matches(fileObject.name)))
yield fileObject
}

}

文件对象
class FileObject(val name: String) {

}

生成文件如下:
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")

有人可以帮我解决问题。提前致谢

最佳答案

您的sbt构建文件不正确。您的scala版本是2.12.x,但是您使用的是在scala 2.11版本中编译的库。使用如下所示的sbt设置

注意:我更改了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
)

记得在sbt控制台中执行 reloadcleancompile来开始干净的编译

关于scala - java.lang.NoClassDefFoundError:scala/Product $ class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42498035/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com