jeval是为为你的Java应用程序提供可加入的、高性能、数学、  布尔和函数表达式的解析和运算的高级资源包。下载jeval的技术文档和源码请到:http://www.oschina.net/?download=jeval

解决方案 »

  1.   

       public static void main(String args[]) {  /*
       * This sample shows the basic usage of the JEval Evaluator class.
       * Calling the default contructor will set he quoteCharater to single
       * quote. This constructor will also load all math variables, math
       * functions and string variables.
       */
      Evaluator evaluator = new Evaluator();  try {   /**
        * 添加变量到 Evaluator 类实例.
        */
       evaluator.putVariable("a", "'Hello'");
       evaluator.putVariable("b", "'World'");   /**
        * 简单输出变量.
        */
       System.out.println(evaluator.evaluate("#{a}"));
       System.out.println(evaluator.evaluate("#{b}"));   /**
        * 简单输出数学常量.
        */
       System.out.println(evaluator.evaluate("#{PI}"));   /**
        * 字符串拼装.
        */
       System.out.println(evaluator.evaluate("#{a} + ' ' + #{b} + '!'"));   /**
        * This sample clears the variables. This call will not clear
        * preloaded variables.
        */
       evaluator.clearVariables();
       /**
        * 自定义变量.
        */
       evaluator.setVariableResolver(new MockVariableResolver());
       System.out.println(evaluator
         .evaluate("#{MockVariable1} + #{MockVariable2}"));
       
       /**
        * This sample shows an invalid expression. The variables were just
        * cleared, therefor the variable "a" no longer exists.
        */
       System.out.println("An exception is expected in the "
         + "next evaluation.");
       System.out.println(evaluator.evaluate("#{a}"));
      } catch (EvaluationException ee) {
       System.out.println(ee);
      }
     }
      

  2.   

    我还是推荐beanshell,可以写java代码,还可以把代码里的类和变量都包括进去
      

  3.   

    evaluator.putVariable("a", "'Hello'");
    evaluator.putVariable("b", "'World'");variableName:是否可以设置成不是final?