javastaticstatic-methodsjexl

How to call a static method of a java class without creating an instance of that class in JEXL?


I want to invoke the static method of a class without putting any object in the context of JEXL.

For instance methods, we put an object to the MapContext and use the key to call the method. but In my case, I don't have anything in context. ${person.howYouDoing()} I don't want to use person object to put in the context.


Solution

  • From the documentation:

    ns:function A JexlEngine can register objects or classes used as function namespaces. This can allow expressions like: math:cosinus(23.0)

    https://commons.apache.org/proper/commons-jexl/reference/syntax.html

    So you have to register a class with JexlEngine