Apache Velocity 2.0 Scripting Compilable无法正常工作

时间:2017-08-16 13:17:52

标签: java velocity scripting-language jsr233 apache-velocity

我试图检查提供JSR 223实现的速度脚本引擎2.0和support of Compilable

  

Compilable界面已在此过程中实施。

我使用jar:velocity-engine-scripting-2.0.jar,velocity-1.7.jar,commons-collections-3.2.2.jar

来自previous answer我使用以下代码

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

对于速度我得到以下内容:

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

此外,当我尝试提供模板名称((Compilable) engine).compile("v.vm");时,它失败并出现相同的异常

1 个答案:

答案 0 :(得分:1)

你不能使用velocity-engine-scripting-2.0.jar和velocity-1.7.jar,你需要使用velocity-engine-core-2.0.jar,否则你会得到不可预知的结果。