title: Apache Velocity - Resource not found exception
body: <p>I have a requirement to generate some automated mails and so I wanted to use velocity for this task.I have copied all velocity jars to the lib folder and created a hello.vm template and placed in WEB-INF/templates folder.Below is exception I am getting,</p>
  
  <pre><code>org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'hello.vm'
  userCount incremented to :1
      at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:474)
      at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352)
      at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533)
      at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1514)
      at org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:373)
      at indian.test.handleRequest(test.java:34)
      at org.apache.velocity.tools.view.VelocityViewServlet.doRequest(VelocityViewServlet.java:217)
      at org.apache.velocity.tools.view.VelocityViewServlet.doGet(VelocityViewServlet.java:182)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at listener.trimresponse.doFilter(trimresponse.java:46)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:619)
  </code></pre>
  
  <p>I tried all the other ways to load resource using classloader/webapps and still the error remains the same.I am using netbeans 7.2.x with tomcat 7.27. Appreciate if someone can suggest something for this.</p>
  
  <p>Below is my velocity properties file,</p>
  
  <pre><code>resource.loader = file
  file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
  file.resource.loader.path = C:\Users\kiran\Desktop\Netbeans Projects\ourstory\web\WEB-INF\templates
  file.resource.loader.cache = true
  file.resource.loader.modificationCheckInterval = 2
  runtime.log=/WEB-INF/logs/velocity.log 
  runtime.log.logsystem.class=org.apache.velocity.runtime.log.Log4JLogSystem
  runtime.log.logsystem.log4j.pattern=%d - %m%n
  runtime.log.logsystem.log4j.file.size=10000
  runtime.log.logsystem.log4j.file.backups=1
  </code></pre>
  
  <p>and below is servlet I am using</p>
  
  <pre><code>import java.util.Properties;
  import javax.servlet.http.*;
  import org.apache.velocity.Template;
  import org.apache.velocity.VelocityContext;
  import org.apache.velocity.app.VelocityEngine;
  import org.apache.velocity.context.Context;
  import org.apache.velocity.tools.view.VelocityViewServlet;
  
  public class test extends VelocityViewServlet {
      private String htmlTemplate = "hello.vm";
  
      VelocityContext context = new VelocityContext();
  
      @Override
      public Template handleRequest(HttpServletRequest request,
              HttpServletResponse response,
              Context context) {
     //    Properties props = new Properties();
      //    props.setProperty("resource.loader", "class");
      //    props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
      //    props.setProperty("webapp.resource.loader.path", "/WEB-INF/templates/");
  
          VelocityEngine engine = new VelocityEngine();
  
  
          engine.init();
  
          Template template = null;
  
          try {
              context.put("name", "Velocity Test");           
                      template = engine.getTemplate(htmlTemplate);
             } catch (Exception e) {
               e.printStackTrace();
              System.err.println("Exception caught: " + e.getMessage());
          }
          return template;
      }
  }
  </code></pre>
  
  <p>its simple servlet but for some reason I am unable to get it working.</p>