tags:

views:

661

answers:

3

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?

A: 

The LogManager source suggests the originating exception is wrapped in the VelocityException. That wrapped exception should give you more info.

Note the related comment in the code.

211         /* If the above failed, that means either the user specified a
212          * logging class that we can't find, there weren't the necessary
213          * dependencies in the classpath for it, or there were the same
214          * problems for the default loggers, log4j and Java1.4+.
215          * Since we really don't know and we want to be sure the user knows
216          * that something went wrong with the logging, let's fall back to the
217          * surefire SystemLogChute. No panicking or failing to log!!
218          */
Brian Agnew
+1  A: 

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.

adding properties.setProperty ("runtime.log.logsystem.class" "org.apache.velocity.runtime.log.NullLogSystem");did the trick
Hamza Yerlikaya
@Hamza: thanks a lot! Adding this setting to velocity.properties solved the problem
Vanya