javavelocityscripting-languagejsr233apache-velocity

Apache Velocity 2.0 Scripting Compilable not working


I'm trying to check velocity scripting engine 2.0 which Provide JSR 223 implementation and support of Compilable

the Compilable interface has been implemented in the process.

I use jars: velocity-engine-scripting-2.0.jar, velocity-1.7.jar, commons-collections-3.2.2.jar

from previous answer I use the following code

//class org.apache.velocity.script.VelocityScriptEngine
final ScriptEngine engine = engineFactory.getScriptEngine();
        if (engine instanceof Compilable) {
            try {
                ((Compilable) engine).compile("");
 ...

For velocity I get the following:

javax.script.ScriptException: org.apache.velocity.exception.ResourceNotFoundException: No template name provided
    at org.apache.velocity.script.VelocityScriptEngine.compile(VelocityScriptEngine.java:311)
    at org.apache.velocity.script.VelocityScriptEngine.compile(VelocityScriptEngine.java:288)
    at com.Workers.LevelCheck.main(LevelCheck.java:69)
Caused by: org.apache.velocity.exception.ResourceNotFoundException: No template name provided
    at org.apache.velocity.runtime.resource.loader.StringResourceLoader.getResourceStream(StringResourceLoader.java:353)
    at org.apache.velocity.Template.process(Template.java:108)
    at org.apache.velocity.script.VelocityScriptEngine.compile(VelocityScriptEngine.java:306)
    ... 2 more

Also when I tried to give template name ((Compilable) engine).compile("v.vm"); it failed with same exception


Solution

  • You cannot use velocity-engine-scripting-2.0.jar with velocity-1.7.jar, you need to use velocity-engine-core-2.0.jar otherwise you'll get unpredictable results.