velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claude Brisson <cla...@renegat.net>
Subject Re: ResourceNotFoundException in IntelliJ IDEA
Date Mon, 21 Mar 2011 20:53:58 GMT
Looks like you would rather need to use the FileResourceLoader. The 
ClasspathResourceLoader is meant to load files which are visible in the 
Java classpath.

   claude

On 2011-03-21 21:44, sasasamamama wrote:
> Hi,
>
> I have a Velocity template ValueTmpl.vm which can't be found by the Velocity
> ResourceManager. A minimal example:
>
>
> package generate;
>
> import java.io.File;
> import java.io.FileWriter;
> import java.io.Writer;
> import org.apache.velocity.app.Velocity;
> import org.apache.velocity.app.VelocityEngine;
> import org.apache.velocity.Template;
> import org.apache.velocity.VelocityContext;
>
> public class Generate {
>      public static void main(String[] args) throws Exception {
>          VelocityContext context = new VelocityContext();
>          context.put("key", "value");
>          Writer writer = new FileWriter(new File("Result.java"));
>          createTemplate("generate/templates/ValueTmpl.vm").merge(context,
> writer);
>          writer.close();
>      }
>
>      private static Template createTemplate(String vmTemplateFile) {
>          VelocityEngine ve = new VelocityEngine();
>          ve.setProperty(Velocity.RESOURCE_LOADER, "class");
>          ve.setProperty("class.resource.loader.class",
>
> "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
>          ve.init();
>          return ve.getTemplate(vmTemplateFile);
>      }
> }
>
>
> The generate folder is in the root of the src directory. I get the following
> error:
>
>
> 21.03.2011 13:09:01 org.apache.velocity.runtime.log.JdkLogChute log
> SEVERE: ResourceManager : unable to find resource
> 'generate/templates/ValueTmpl.vm' in any resource loader.
> Exception in thread "main"
> org.apache.velocity.exception.ResourceNotFoundException
>
>
> Does someone know what the problem can be? Should I change something in the
> project settings?
>
> Thanks in advance!
>
>
> (I am sorry if this is the second time you get this message -- seems like
> the last one failed to be sent)


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Mime
View raw message