问题
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