I write the following class:

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;
    }
}

But the I create object of this class I have the foolowing error:

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

on first line of the constructor (when create an object of JexlEngine):

public NelderMead(String funcString){
    this.jexl = new JexlEngine();
    this.setFunc(funcString);
}

Could you help me - why this code cause the errors?

PS I use .jar file to use this lib.

有帮助吗?

解决方案

You need to make commons-logging jar available in classpath at runtime

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top