Apache Velocity can not Initialize
22,052
Solution 1
try something like this:
Properties p = new Properties();
p.setProperty("resource.loader", "class");
p.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader");
p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
try {
Velocity.init(p);
} catch(...., and handle excpetion
}
you'll now be able to call:
VelocityContext vContext = new VelocityContext(context);
//put things into vContext
StringWriter sw = new StringWriter();
try {
template.merge(vContext, sw);
etc.
Solution 2
The problem was solved putting the code below in my app:
java.util.Properties p = new java.util.Properties();
p.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
try {
Velocity.init(p);
} catch (Exception e) {
System.out.println("FAIL!");
}
Author by
Hamza Yerlikaya
Updated on February 19, 2020Comments
-
Hamza Yerlikaya over 4 years
When i try to initialize velocity engine using
VelocityEngine engine = new VelocityEngine(); engine.init();
I encounter the same error when i try
Velocity.init();
org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.ServletLogChute with the current runtime configuration.
What may cause this exception?