You cannot do this in a given TLD function, but you can put an object in the application area (once, at startup) using the varags method and / or overloaded methods and work fine.
Instead of defining it in a TLD, you can create an instance of your class in your init() method and place it in the application (servlet) area, for example:
MyDiceRoller roller = new MyDiceRoller(); ServletContext context = getServletContext(); context.setAttribute("roller", roller);
Then, instead of ${my:rollIt(6)} you do ${roller.rollIt(6)} . And instead of ${my:rollIt()} you would do ${roller.rollIt()} .
source share