我写了以下课程:
import org.apache.commons.jexl2.*;
public class NelderMead {
// контсанты
private static int M = 3;
private static double E = 0.005;
private static double A = 1.000;
private static double B = 0.500;
private static double Y = 2.000;
// переменные
private JexlEngine jexl = new JexlEngine();
private Expression func;
private String funcString = "";
private MapContext[] iterations;
public NelderMead(){
this.jexl = new JexlEngine();
}
public NelderMead(String funcString){
this.jexl = new JexlEngine();
this.setFunc(funcString);
}
public void setFunc(String funcString){
this.funcString = funcString;
this.func = this.jexl.createExpression(funcString);
}
public double funcEval(MapContext args){
return (Double) this.func.evaluate(args);
}
public boolean checkCriterian(){
return true;
}
}
但是我创建这个类的对象我有一个愚蠢的错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.commons.jexl2.JexlEngine$UberspectHolder.<clinit>(JexlEngine.java:121)
at org.apache.commons.jexl2.JexlEngine.getUberspect(JexlEngine.java:205)
at org.apache.commons.jexl2.JexlEngine.<init>(JexlEngine.java:182)
at org.apache.commons.jexl2.JexlEngine.<init>(JexlEngine.java:170)
at NelderMead.<init>(NelderMead.java:22)
at Test.main(Test.java:10)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 6 more
在构造函数的第一行(创建 JexlEngine 的对象时):
public NelderMead(String funcString){
this.jexl = new JexlEngine();
this.setFunc(funcString);
}
你能帮我吗 - 为什么这段代码会导致错误?
PS 我使用 .jar 文件来使用这个库。