Velocity with External Properties : Velocity Properties « Velocity « Java






Velocity with External Properties


import java.io.StringWriter;
import java.io.Writer;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

public class HelloWorldExternalProperties {

  public static void main(String[] args) throws Exception {
    Velocity.init("./src/velocity.properties");

    Template template = Velocity.getTemplate("./src/HelloWorld.vm");

    VelocityContext context = new VelocityContext();

    Writer writer = new StringWriter();
    template.merge(context, writer);

    System.out.println(writer.toString());
  }
}
-------------------------------------------------------------------------------------
#
# This is a simple example of a velocity properties file.
#
# Any property that is not listed here will have it's default
# value used.  The default values are located in :
#  *  src/java/org/apache/velocity/runtime/default/velocity.defaults
#  *  http://jakarta.apache.org/velocity/developer-guide.html
#
# as an example, we are changing the name of the velocity log 
#
runtime.log = velocity_example.log


-------------------------------------------------------------------------------------
Hello World!
           
       








velocity-HelloWorldExternalProperties.zip( 795 k)

Related examples in the same category

1.Use java.util.Properties to pass in properties