|
Re: Newbie - Keep getting ResourceNotFoundException: msg#00222jakarta.velocity.user
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> |
|---|---|---|
| Previous by Date: | 2 macros with the same name allowed?: 00222, Rodney Schneider |
|---|---|
| Next by Date: | Re: 2 macros with the same name allowed?: 00222, Geir Magnusson Jr . |
| Previous by Thread: | Re: Re[2]: Newbie - Keep getting ResourceNotFoundExceptioni: 00222, Geir Magnusson Jr . |
| Next by Thread: | Setting Variables: 00222, Peter Harrison |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |