You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by sasasamamama <sa...@ya.ru> on 2011/03/21 21:44:21 UTC

ResourceNotFoundException in IntelliJ IDEA

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)
-- 
View this message in context: http://old.nabble.com/ResourceNotFoundException-in-IntelliJ-IDEA-tp31202777p31202777.html
Sent from the Velocity - User mailing list archive at Nabble.com.


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


Re: ResourceNotFoundException in IntelliJ IDEA

Posted by teemu kanstren <tk...@gmail.com>.
What are your settings to get your .vm templates copied into the project
compilation folder? Check that it uses pattern .vm to copy your stuff. Then
use a loader like classpath resource loader to get there.. But check your
compilation dir that it has the .vm files and in the path you are trying to
load (and that this is actually accessible in the classpath).

2011/3/22 marianna <sa...@yandex.ru>

> Thank you Claude, I tried to use the FileResourceLoader, but it didn't
> change anything. For some reason, it worked after I had removed everything
> related to the VelocityEngine and just wrote something like
>
> Template t0 = Velocity.getTemplate("src/generate/templates/ValueTmpl.vm");
> t0.merge(context, writer);
>
>
>
> 21.03.2011, 23:53, "Claude Brisson" <cl...@renegat.net>:
> > 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

Re: ResourceNotFoundException in IntelliJ IDEA

Posted by marianna <sa...@yandex.ru>.
Thank you Claude, I tried to use the FileResourceLoader, but it didn't change anything. For some reason, it worked after I had removed everything related to the VelocityEngine and just wrote something like

Template t0 = Velocity.getTemplate("src/generate/templates/ValueTmpl.vm");
t0.merge(context, writer);



21.03.2011, 23:53, "Claude Brisson" <cl...@renegat.net>:
> 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

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


Re: ResourceNotFoundException in IntelliJ IDEA

Posted by Claude Brisson <cl...@renegat.net>.
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