我想在Java中调用以下Scala代码:
Scala代码
package calculate
import java.io._
class CalculationScala
object CalculationScala {
def main(args: Array[String]) {
def operate(a: Double, b: Double, op: (Double, Double) => Double): Double = (op(a, b))
println(operate(5, 15, _-_))
}
}
Java代码
package calculate;
public class Calculation {
public static void main(String[] args) {
CalculationScala calculationScala = new CalculationScala();
calculationScala.main(args);
}
}
但发生以下错误。
错误
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Function2
at calculate.CalculationScala.main(CalculationScala.scala)
at calculate.Calculation.main(Calculation.java:79)
Caused by: java.lang.ClassNotFoundException: scala.Function2
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 2 more
如何解决这个问题?
答案 0 :(得分:2)
看起来您在运行时类路径上缺少scala-library.jar。