Apache Velocity 2.0 Scripting Compilable not working

醉酒当歌 提交于 2019-12-13 00:06:44

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/45714690/apache-velocity-2-0-scripting-compilable-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!