http://www.beanshell.org/manual/bshmanual.htm
http://www.beanshell.org/javadoc/bsh/util/package-summary.htmll
http://www.beanshell.org/download.html
简单demo:
public class BeanShellUtil {
public static double countMathExpress(String exp) {
double retVal = 0d;
Interpreter interpreter = new Interpreter();
try {
interpreter.eval("result=" + exp);
retVal = Double.parseDouble(interpreter.get("result").toString());
} catch (Exception e) {
e.printStackTrace();
}
return retVal;
}
public static void main(String[] args) {
System.out.println(countMathExpress("4+7*4"));
}
}