• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Exception: Unable to find resource '/WEB-INF/templates/hello.vm'

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working through a velocity tutorial and I'm using velocity 1.6 along with tomcat 6 and working in a Eclipse Galileo IDE. I'm getting the following when I try to execute my first VelocityViewServlet for the first time:

Exception: Unable to find resource '/WEB-INF/templates/hello.vm' [Ljava.lang.StackTraceElement;@15d17d7
Mar 23, 2010 9:09:45 AM org.apache.catalina.core.ApplicationContext log
INFO: Velocity [warn] VelocityViewServlet: couldn't find template to match request.

I have already tried several variations of setting the resource loader and the classpath to my template dynamically instead of using a velocity.properties file, which didn't work either previously. So I would appreciate any suggestions for me to try to resovle this issue. I previously tried to find something in the frameworks forum and didn't find subject lines that stood out, though I did go through the posts rather fast.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without knowing what you've actually tried or are doing, it's pretty difficult to help.
 
Henry Versemann
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm currently trying to work my way through the simple velocity tutorial at http://www.javaranch.com/journal/2004/03/Velocity-AnIntroduction.html and cannot get velocity to see the "hello.vm" template file when the statement template=Velocity.getTemplate("hello.vm") is executed in the "HelloTest.java" servlet listed on page three of the tutorial. Tomcat 6 seems to startup ok with no errors or exceptions, but when I actually try to access my servlet I get this warning:

WARN main org.apache.commons.digester.Digester - [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:velocity' did not find a matching property.

Not sure if the warning is important at this point because I get it both when I startup Tomcat standalone or via eclipse. Later I see that the /WEN-INF/velocity.properties is being looked for like this:

15:42:09,671 INFO http-8282-1 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/velocity] - Velocity [debug] VelocityViewServlet: Looking for custom properties at '/WEB-INF/velocity.properties'
15:42:09,671 INFO http-8282-1 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/velocity] - Velocity [debug] VelocityViewServlet: No custom properties found. Using default Velocity configuration.

and I purposely did not specify one for startup, because I wanted to specify some properties dynamically in my servlet. Next I see where the velocimacro library is being looked for:

Velocimacro : initialization starting.
15:42:09,734 INFO http-8282-1 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/velocity] - Velocity [debug] Velocimacro : "velocimacro.library" is not set. Trying default library: VM_global_library.vm
15:42:09,734 INFO http-8282-1 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/velocity] - Velocity [debug] Velocimacro : Default library not found.

its apparently not found, even though I have had it both immediately under /WEB-INF as well as in /WEB-INF/templates where I've also seen that its also possible to put it, and it seems like sometimes it finds it and sometimes it doesn't. Next the toolbox.xml specified in my web.xml isn't found either though it is defined in the web.xml:

RuntimeInstance successfully initialized.
15:42:09,734 INFO http-8282-1 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/velocity] - Velocity [debug] VelocityViewServlet: No toolbox entry in configuration. Looking for '/WEB-INF/toolbox.xml'
15:42:09,781 INFO http-8282-1 org.apache.velocity.tools.view.servlet.ServletToolboxManager - Using config file '/WEB-INF/toolbox.xml'

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>velocity</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>velocity</servlet-name>
<servlet-class>
org.apache.velocity.tools.view.servlet.VelocityViewServlet
</servlet-class>
<init-param>
<param-name>org.apache.velocity.toolbox</param-name>
<param-value>/WEB-INF/toolbox.xml</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
<servlet>
<description></description>
<display-name>HelloTest</display-name>
<servlet-name>HelloTest</servlet-name>
<servlet-class>servlets.HelloTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloTest</servlet-name>
<url-pattern>/HelloTest</url-pattern>
</servlet-mapping>
</web-app>

once it reaches this point in the process then I start getting exceptions which look like they're related to some of the tools specified in the toolbox like this:

ERROR http-8282-1 org.apache.velocity.tools.view.ViewToolInfo - Exception when calling init(Object) on org.apache.velocity.tools.struts.MessageTool@15dd910
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

ERROR http-8282-1 org.apache.velocity.tools.view.ViewToolInfo - Exception when calling init(Object) on org.apache.velocity.tools.struts.ActionMessagesTool@1ae90c
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

ERROR http-8282-1 org.apache.velocity.tools.view.ViewToolInfo - Exception when calling init(Object) on org.apache.velocity.tools.struts.ErrorsTool@ba4211
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source

ERROR http-8282-1 org.apache.velocity.tools.view.ViewToolInfo - Exception when calling init(Object) on org.apache.velocity.tools.struts.ValidatorTool@47a0d4
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

and the process finally finishes up running like this:

at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at org.apache.velocity.tools.struts.ValidatorTool.init(ValidatorTool.java:188)
... 23 more
15:42:09,859 INFO http-8282-1 servlets.HelloTest - Beginning HelloTest
15:42:09,859 INFO http-8282-1 servlets.HelloTest - returning from HelloTest
15:42:09,859 INFO http-8282-1 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/velocity] - Velocity [warn] VelocityViewServlet: couldn't find template to match request.


I would appreciate any help on figuring this out. Let me know if anymore information is needed. I tried as much as possible to do everything mentioned in the setup or steps mentioned in this tutorial. More of my files are show below:

HelloTest.java:

package servlets;

import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.context.Context;
import org.apache.velocity.tools.view.servlet.VelocityViewServlet;

public class HelloTest extends VelocityViewServlet {

/**
*
*/
private static final long serialVersionUID = -8731237619567372345L;

public Template handleRequest( HttpServletRequest request,
HttpServletResponse response,
Context context ) {
Logger logger = Logger.getLogger(HelloTest.class);

logger.info("Beginning HelloTest");

Properties p = new Properties();

p.setProperty( "resource.loader", "class" );
p.setProperty( "class.resource.loader.class",
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader" );
p.setProperty( "class.resource.loader.path",
"/WEB-INF/templates");
//"C:/Tomcat/apache-tomcat-6.0.26/webapps/velocity/WEB-INF/templates");
p.setProperty( "class.resource.loader.cache", "true");
p.setProperty( "class.resource.loader.modificationCheckInterval","5");

try{
Velocity.init(p);
}
catch(Exception e){
System.err.println("Velocity Engine Start Exception: " + e.getMessage());
}

Template template = null;

try {
context.put("name", "Velocity Test");
template = Velocity.getTemplate("hello.vm");
} catch( Exception e ) {
System.err.println("Exception: " + e.getMessage() + e.getStackTrace());
}

logger.info("returning from HelloTest");

return template;
}
}


toolbox.xml:

<?xml version="1.0" encoding="UTF-8"?>
<toolbox>
<tool>
<key>link</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.StrutsLinkTool</class>
</tool>
<tool>
<key>text</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.MessageTool</class>
</tool>
<tool>
<key>messages</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.ActionMessagesTool</class>
</tool>
<tool>
<key>errors</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.ErrorsTool</class>
</tool>
<tool>
<key>form</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.FormTool</class>
</tool>
<tool>
<key>validator</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.ValidatorTool</class>
</tool>
</toolbox>


hello.vm:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>hello</title>
</head>
<body>
Hello $name
</body>
</html>


VM_global_library.vm:

#macro(onecolumnrow)
<tr><td></td></tr>
#end


My environment is as follows:

Eclipse Galileo
Tomcat 6
Velocity 1.6.3
Log4j-1.2.12



























Then when I enter my url "http://localhost:8282/velocity/HelloTest".
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.

You can edit your post by using the button.
 
Henry Versemann
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have made significant progress through a lot of research that I have been doing in the web. As it stands right now I can access my templates directly by url requests made through IE(like: [u]http://localhost:8282/velocity/hello.vm ). However the problem I'm still having is trying to run the following statement from within the HelloTest servlet(from tutorial at http://www.javaranch.com/journal/2004/03/Velocity-AnIntroduction.html): template = Velocity.getTemplate("hello.vm");
I am currently using the ClasspathResourceLoader, and have my raw templates in /WEB-INF/templates, and also have jar'd my templates and placed them in /WEB-INF/lib as described in some of the documentation, when using ClasspathResourceLoader. I can request and also see them by requesting them directly like this: http://localhost:8282/velocity/hello.vm. The problem seems to arise when the servlet tries to get the template(s). So now the next question is is the problem something that can or has to be fixed in the servlet, or in the servlet's entry in the web.xml? I'm running this Velocity webapp in Tomcat 6 within an Eclipse Galileo environment. I have attached my web.xml. My hello.vm (same as code from the tutorial) is at WEB-INF/templates in the project and also jar'd and in the WEB-INF/lib (for classpathResourceLoader) folder of the project. My HelloTest.java (same as code from tutorial) is at src/servlets in the project.

Here's how the velocity.properties file is coded:

resource.loader = class
class.resource.loader.description = Velocity Classpath resource Loader
class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
class.resource.loader.path = ../WEB-INF/lib, ../WEB-INF/templates
class.resource.loader.cache = false
class.resource.loader.modificationCheckInterval = 5
velocimacro.library =
velocimacro.permissions.allow.inline = true
velocimacro.permissions.allow.inline.to.replace.global = false
velocimacro.permissions.allow.inline.local.scope = false
velocimacro.context.localscope = false

When I request the the template via the HelloTest servlet I get the last four lines of the following console output in return:

2010-03-26 15:57:31,847{HH:mm:ss,SSS INFO http-8282-1 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/velocity] - Velocity [debug] VelocityViewServlet: No toolbox entry in configuration. Looking for '/WEB-INF/toolbox.xml'

2010-03-26 15:57:31,847{HH:mm:ss,SSS INFO http-8282-1 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/velocity] - Velocity [info] VelocityViewServlet: Default content-type is: text/html

2010-03-26 15:57:31,863{HH:mm:ss,SSS INFO http-8282-1 servlets.HelloTest - Beginning HelloTest

2010-03-26 15:57:31,910{HH:mm:ss,SSS INFO http-8282-1 servlets.HelloTest - Exception: Unable to find resource 'hello.vm'[Ljava.lang.StackTraceElement;@9a8a68

2010-03-26 15:57:31,910{HH:mm:ss,SSS INFO http-8282-1 servlets.HelloTest - returning from HelloTest

2010-03-26 15:57:31,910{HH:mm:ss,SSS INFO http-8282-1 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/velocity] - Velocity [warn] VelocityViewServlet: couldn't find template to match request.


Please let me know if there's anything else I haven't included which would be helpful in trying to debug this issue. Thanks.

Henry

 
Why is the word "abbreviation" so long? And this ad is so short?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic