Failed to initialize an instance of org.apache.velocity.runtime.log. ServletLogChute with the current runtime configuration.

This is another problem I went into where I was trying to use apache velocity template for sendinng mails using pre-defined templates. Everything looked fine until I ran into the issue which threw the error
org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.ServletLogChute with the current runtime configuration.

The velocity template is very easy to use. below is a sample code to use Velocity template:

This works perfectly fine if you are running the application on your local system where you have sufficient permissions.

When the application is to be deployed on a highly secure system where permissions are not very easy to grant. IN such a system you might get this error.

Cause of this error:
With all the default settings, Velocity tries to write a log file named velocity.log in the same directory from where tomcat server is started. In case where the tomcat server is not started from /tomcat/server/bin and you choose a different folder where you don’t have write permissions you get this error.

Solution:

You can replace the initialization part of Velocity with the following code:

How to reproduce this error in local development environment:
You can actually run tomcat from some other directory.

  • Open up command prompt on windows.
  • Navigate to some directory from where you wish to run tomcat.
  • Run the command %CATALINA_HOME%/server/bin/startup.bat
  • It will throws the error Failed to initialize an instance of org.apache.velocity.runtime.log.ServletLogChute with the current runtime configuration. when Velocity tries to initialize.
  • There are few more references which might help people.

    http://stackoverflow.com/questions/1586133/apache-velocity-can-not-initialize
    http://stackoverflow.com/questions/849710/error-in-velocity-and-log4j

    and many more

    Hope this helps, Happy coding. Stay connected and stay Subscribed

  • Nit

    Thanks man..it helped me…

  • What is LOGGER_NAME in your code?

  • dharam

    I do not remember completely, but I am sure it was the name of the class. Always instantiated logger using Logger log = Logger.getInstance(MyClass.class.getName());