[英]Why do I get `java.lang.NoClassDefFoundError: scala/Function1` when I run my code in ScalaIDE?
Here is a simple test I'm using to invoke a Scala method from Java: 这是我用来从Java调用Scala方法的简单测试:
public static void main(String args[]) {
java.util.Map<String, java.util.List<String>> rec = news.recommend.DriverObj.runTest();
System.out.println(rec.toString());
}
Here is the definition of the Scala method: 以下是Scala方法的定义:
def runTest: java.util.Map[String, java.util.List[String]] = {
new java.util.HashMap[String, java.util.List[String]]
}
But it throws an error: 但它抛出一个错误:
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Function1
at news.recommend.DriverObj.runTest(DriverObj.scala)
What should I do to make this running smoothly? 我该怎么做才能让它顺利运行?
Update : I'm running it via Eclipse and my build path contains : 更新:我通过Eclipse运行它,我的构建路径包含:
So Scala library should be found ? 那么应该找到Scala库?
adding the Scala dependency to the maven build can fix the issue : 将Scala依赖项添加到maven构建可以解决此问题:
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.3</version>
</dependency>
As for me, in the configuration of "Run/Debug configurations" [idealJ] 至于我,在“运行/调试配置”的配置中[idealJ]
remember to choose the "Include dependencies with "Provided" scope" 记得选择“包含依赖关系”提供“范围”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.