You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Shivani Sawhney <sh...@netedgecomputing.com> on 2005/11/12 08:07:41 UTC

Velocity: ResourceNotFoundException

Hi,

I am new to this mailing list and am using velocity in my current
project. I am facing a problem providing a template to velocity engine.
The code is listed below:

VelocityContext context = new VelocityContext(); 
context.put("OfferLetterDTO", objOfferLetterDTO); 
Template template = null; 

            try 
            { 
                System.out.println((new
File(templateFile)).getAbsolutePath() + (new
File(templateFile)).exists()); 
               [b] template = Velocity.getTemplate(templateFile);[/b] 
            } catch (ResourceNotFoundException rnfe) 
            { 
                System.out.println("CreateAttachmentFromTemplate : error
: cannot find template " + templateFile); 
            } catch (ParseErrorException pee) 
            { 
                System.out.println("CreateAttachmentFromTemplate :
Syntax error in template " + templateFile + ":" + pee); 
            }




The problem is with the line "template =
Velocity.getTemplate(templateFile);" 
If a pass an absolute path, lets say, "E:\Resource\templates\a.html",
the error that I get is "ResourceNotFoundException" though the file
actually exists in the same path. The same code works fine if I give a
relative path. I am using JBoss and its trying to find the template file
relative to "{JBoss-home}/bin". 
Is there any way that i can pass an absolute path to this method. The
velocity API says the getTemplate(java.lang.String name) method 
"Returns a Template from the Velocity resource management system." and I
fail to understand what "Velocity resource management system" means. 

Hope that someone can help find a solution. 

Thanks in advance.

 

Regards,

Shivani


Re: Velocity: ResourceNotFoundException

Posted by Nathan Bubna <nb...@gmail.com>.
have you read this?

http://jakarta.apache.org/velocity/docs/developer-guide.html#Configuring%20Resource%20Loaders

you must configure your resource loader with the proper template root
directory.  by default it uses the current directory Velocity is
running from as the root.  all template requests must be relative to
the root directory, rather than absolute.

On 11/11/05, Shivani Sawhney <sh...@netedgecomputing.com> wrote:
> Hi,
>
> I am new to this mailing list and am using velocity in my current
> project. I am facing a problem providing a template to velocity engine.
> The code is listed below:
>
> VelocityContext context = new VelocityContext();
> context.put("OfferLetterDTO", objOfferLetterDTO);
> Template template = null;
>
>             try
>             {
>                 System.out.println((new
> File(templateFile)).getAbsolutePath() + (new
> File(templateFile)).exists());
>                [b] template = Velocity.getTemplate(templateFile);[/b]
>             } catch (ResourceNotFoundException rnfe)
>             {
>                 System.out.println("CreateAttachmentFromTemplate : error
> : cannot find template " + templateFile);
>             } catch (ParseErrorException pee)
>             {
>                 System.out.println("CreateAttachmentFromTemplate :
> Syntax error in template " + templateFile + ":" + pee);
>             }
>
>
>
>
> The problem is with the line "template =
> Velocity.getTemplate(templateFile);"
> If a pass an absolute path, lets say, "E:\Resource\templates\a.html",
> the error that I get is "ResourceNotFoundException" though the file
> actually exists in the same path. The same code works fine if I give a
> relative path. I am using JBoss and its trying to find the template file
> relative to "{JBoss-home}/bin".
> Is there any way that i can pass an absolute path to this method. The
> velocity API says the getTemplate(java.lang.String name) method
> "Returns a Template from the Velocity resource management system." and I
> fail to understand what "Velocity resource management system" means.
>
> Hope that someone can help find a solution.
>
> Thanks in advance.
>
>
>
> Regards,
>
> Shivani
>
>
>

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