7

When instatiating Velocity I get this error (posted just the "caused by"-messages):

java.lang.RuntimeException: Velocity could not be initialized!
Caused by: org.apache.velocity.exception.VelocityException: Error initializing log: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
Caused by: org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute : 
Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)

This is my code snippet:

    VelocityEngine ve = new VelocityEngine();
    ve.evaluate(context, writer, "org.apache.velocity.runtime.log.NullLogChute", this.templateString);

At first my code looked like this:

runtimeServices = RuntimeSingleton.getRuntimeServices();
node = runtimeServices.parse(reader, templateName);

On my Windows machine it works fine, but on Linux systems (ubuntu 10.04) it doesn't work. This post doesn't help me much, since I haven't found any clues which directory I have to give write-permissions.

I found out, that the following code is working also at Linux machines:

String logPath = request.getRealPath("/velocity.log");
RuntimeSingleton.setProperty( RuntimeConstants.RUNTIME_LOG, logPath );
runtimeServices = RuntimeSingleton.getRuntimeServices();
node = runtimeServices.parse(reader, templateName);

It is not a very nice solution, since I could never be sure, if I have write permission on my real context path. The best would be, just turning off logging of Velocity.

What different different logging configuration do I have to set? Is the NullLogChute just not working or do I use it inappropriate?

Thanks in advance!

Community
  • 1
  • 1
Franz
  • 119
  • 3
  • 8

1 Answers1

-1

Hi the problem is on fs protected in write permission. Infact in your stacktrace you have:

java.io.FileNotFoundException: velocity.log (Permission denied)

So it's good stuff decide where velocity log will be written. And you say a good word, you cant know if in production you can write to a specific path. So it is better put that path in a properties file that sysadmin can modify as he want.

So check this my answer to another post if can help you.

Link here

Community
  • 1
  • 1