logo       

Re: Newbie - Keep getting ResourceNotFoundException: msg#00222

jakarta.velocity.user

Subject: Re: Newbie - Keep getting ResourceNotFoundException

Hi Soren,

Sorry, my keyboard doesn't do the / and o as one as used in Scandinavia.

I had the same problem. Velocity looks for the vm file in the same directory
it tries to write the velocity.log to. In my case it was $TOMCAT_HOME/bin.
Crazy, isn't it?

I found the cure in an example. Add this to your code below:
/**
* Called by the VelocityServlet
* init(). We want to set a set of properties
* so that templates will be found in the webapp
* root. This makes this easier to work with as
* an example, so a new user doesn't have to worry
* about config issues when first figuring things
* out
*/
protected Properties loadConfiguration(ServletConfig config )
throws IOException, FileNotFoundException
{
Properties props = new Properties();

/*
* first, we set the template path for the
* FileResourceLoader to the root of your
* web application. This should work under tomcat
*/

String path = config.getServletContext().getRealPath("/");

if (path == null)
{
System.out.println(" SampleServlet.loadConfiguration() : unable to
"
+ "get the current webapp root. Using '/'.
Please fix.");

path = "/";
}

props.setProperty( Velocity.FILE_RESOURCE_LOADER_PATH, path );

/**
* and the same for the log file
*/

props.setProperty( "runtime.log", path + "velocity.log" );

return props;
}

It worked and velocity.log is then written to the root directory of your
specific web application. That's where your vm file should also be.

Hope it helps.

On Wed 27 Nov 02 6:36, Søren Neigaard wrote:
> I'm trying to make a simple HelloWorld example, and I'm doing this
> from inside the doGet method in a servlet:
>
> ------------------
> Velocity.init();
> VelocityContext context = new VelocityContext();
> context.put("name", new String("Velocity Test"));
> Template template = null;
> try {
> template = Velocity.getTemplate("mytemplate.vm");
> template.merge(context,response.getWriter());
> }
> catch(Exception e){
> e.printStackTrace();
> }
> ------------------
>
> Where does it look for the template? Can it be on the file system, or
> must it be accessible via HTTP? I have now tried to pint it directly
> to the path where the file is, and i get this error:

Chris Malan
malan2000@xxxxxxxxxxxxxxx


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise