パッケージに数学クラスがありますmypackage
。ここで、このクラスを MVEL にインポートし、そのプロパティに値を割り当てて、そのメソッドにアクセスしたいと考えています。次のコードを作成しましたが、次のようなエラーが発生します
Exception in thread "main" [Error: unknown class or illegal statement:
^
コードは
ParserContext context = new ParserContext();
context.addImport("math",mypackage.MyMaths.class);//MyMaths.class is public
context.addInput("obj", mypackage.MyMaths.class);
String expression1 = "obj.a == 20";//a is public property
Serializable compiled1 = MVEL.compileExpression(expression1,context);
MVEL.executeExpression(compiled1);