Share on Google+Share on Google+

How to pass java.util.Properties in properties

This Example shows you how to use java.util.Properties to in velocity.

How to pass java.util.Properties in properties


This Example shows you how to use java.util.Properties to in velocity. The methods used in this example are described below:- 
1:- Initialize velocity run time engine through method  init().
2:- Create object of VelocityContext Class.
3:- Create Template class object, Template  class object is used for controlling template methods and properties.

In this example we have used method init() with parameter of type Properties type that initialize velocity runtime engine with default properties plus properties passed as parameter in init() method. 

template.merge(context, writer): Merge method of the Template class is used here for merging  the VelocityContext class object to produce the output.

import java.util.Properties;

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

public class PassProperties {

  public static void main(String[] argsthrows Exception {
  Properties props = new Properties();


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

  VelocityContext context = new VelocityContext();

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


Hi,this is Komal Choudhary

Hi,this is Komal Choudhary

Download code



Posted on: August 27, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: How to pass java.util.Properties in properties  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image