我正在尝试运行Scala Junit 4测试,但我得到了NoClassDefFoundError: scala/Function1
。我通过运行配置启动它。
任何人都知道这是什么问题?
完整错误:
java.lang.NoClassDefFoundError: scala/Function1
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.isJUnit3SetUpTest(JUnit4TestLoader.java:61)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:49)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: scala.Function1
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 12 more
答案 0 :(得分:2)
我遇到类似的问题,当我使用akka-http-2.11
构建的scala 2.11.*
时,我在类路径中使用scala-2.12.4
。
错误是
java.lang.NoClassDefFoundError: scala/Function1$class
at akka.stream.Supervision$$anon$1.<init>(Supervision.scala:57)
at akka.stream.Supervision$.<init>(Supervision.scala:57)
at akka.stream.ActorMaterializerSettings$.apply(ActorMaterializer.scala:258)
at akka.stream.ActorMaterializerSettings$.apply(ActorMaterializer.scala:248)
at akka.stream.ActorMaterializer$$anonfun$1.apply(ActorMaterializer.scala:41)
at akka.stream.ActorMaterializer$$anonfun$1.apply(ActorMaterializer.scala:41)
at scala.Option.getOrElse(Option.scala:121)
at akka.stream.ActorMaterializer$.apply(ActorMaterializer.scala:41)
at akka.stream.ActorMaterializer$.create(ActorMaterializer.scala:110)
(请参阅下面的build.gradle
)
dependencies {
compile group: 'org.scala-lang', name: 'scala-library', version: '2.12.4'
compile group: 'com.typesafe.akka', name: 'akka-actor_2.12', version: '2.5.6'
compile group: 'com.typesafe.akka', name: 'akka-http-experimental_2.11', version: '2.4.11.2'
}
FIX是在所有依赖项中使用相同版本的scala(2.11
)。
dependencies {
compile group: 'org.scala-lang', name: 'scala-library', version: '2.11.11'
compile group: 'com.typesafe.akka', name: 'akka-actor_2.12', version: '2.5.6'
compile group: 'com.typesafe.akka', name: 'akka-http-experimental_2.11', version: '2.4.11.2'
}
因此,请确保使用相同版本的scala。