title: Unable to display instance variables of object in Apache velocity
body: <p>I'm trying to display some info using Apache velocity , however it does not seem to work.</p>
  
  <p>Follwing is the code snippet.</p>
  
  <pre><code>package velocitydemo;
  
  import java.io.StringWriter;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.velocity.Template;
  import org.apache.velocity.VelocityContext;
  import org.apache.velocity.app.VelocityEngine;
  
  class Vehicle {
      private String vname;
      private Wheel wheel;
      private String type;    
      /**
       * @return the vname
       */
      public String getVname() {
          return vname;
      }
  
      /**
       * @param vname the vname to set
       */
      public void setVname(String vname) {
          this.vname = vname;
      }
  
      /**
       * @return the wheel
       */
      public Wheel getWheel() {
          return wheel;
      }
  
      /**
       * @param wheel the wheel to set
       */
      public void setWheel(Wheel wheel) {
          this.wheel = wheel;
      }
  
      /**
       * @return the type
       */
      public String getType() {
          return type;
      }
  
      /**
       * @param type the type to set
       */
      public void setType(String type) {
          this.type = type;
      }
  
      /**
       * @return the model
       */
      public int getModel() {
          return model;
      }
  
      /**
       * @param model the model to set
       */
      public void setModel(int model) {
          this.model = model;
      }
  
      private int model;
  
      public Vehicle(String name, Wheel wheel, String type, int model) {
          super();
          this.vname = name;
          this.wheel = wheel;
          this.type = type;
          this.model = model;
      }
  }
  
  class Wheel {
      private String type;
      private String name;
  
      /**
       * @return the type
       */
      public String getType() {
          return type;
      }
  
      /**
       * @param type the type to set
       */
      public void setType(String type) {
          this.type = type;
      }
  
      /**
       * @return the name
       */
      public String getName() {
          return name;
      }
  
      /**
       * @param name the name to set
       */
      public void setName(String name) {
          this.name = name;
      }
  
      public Wheel(String type, String name) {
          super();
          this.type = type;
          this.name = name;
      }
  }
  
  public class HelloWorld {
      private static List&lt;String&gt; list = new ArrayList&lt;String&gt;();
  
      public static void main(String[] args) throws Exception {
  
          Vehicle vh = constructVehicle("Model S", "Vinyl", "JK", "Electric", 2014);
  
          VelocityEngine ve = new VelocityEngine();
          ve.init();
          /* next, get the Template */
          Template t = ve.getTemplate("helloworld.vm");
          /* create a context and add data */
          VelocityContext context = new VelocityContext();
          context.put("name", "World");
          context.put("name2", "foobar");
          context.put("name3", "flash");
          context.put("vehicle", vh);
          StringWriter writer = new StringWriter();
          t.merge(context, writer);
          System.out.println(writer.toString());
      }
  
      public static Vehicle constructVehicle(String vehicleName, String wheelType, String wheelName, String vhType, int model) {
          Wheel wl = new Wheel(wheelType, wheelName);
          Vehicle vh = new Vehicle(vehicleName, wl, vhType, model);
  
          return vh;
      }
  }
  </code></pre>
  
  <p>The velocity template is helloworld.vm with the following info</p>
  
  <pre><code>Hello $name!  Welcome to Velocity!
  Hello $name2!  Welcome to Velocity!
  Hello $name3!  Welcome to Velocity!
  Car is  $vehicle.vname
  Car is  $vehicle.getVname()
  Car is  $vehicle.hashCode()  and model is $vehicle.getModel()
  </code></pre>
  
  <p>However the output is :</p>
  
  <pre><code>Hello World!  Welcome to Velocity!
  Hello foobar!  Welcome to Velocity!
  Hello flash!  Welcome to Velocity!
  
  
  Car is  $vehicle.vname
  Car is  $vehicle.getVname()
  Car is  14872264  and model is $vehicle.getModel()
  </code></pre>
  
  <p>I don't understand why variables of class Vehicle are not getting resolved.</p>