Re: Velocity into a plug-in

jian chen <[email protected]>
Newsgroups gmane.comp.jakarta.velocity.user
Message-ID <CAC78mAOi5s6yfJ7c8y9dfrGKcbF2k_C2yL29C07wiG0Zaie+NQ@mail.gmail.com>
Hi Vanessa,

It looks to me that you are relying on the default way that Velocity
loads its templates. I am not sure if it is loading from classpath?

But, typically I would use more explicit way to load templates, for
example, just use the file system path like this:

File templateDir = new File("/path/to/template");
ve = new VelocityEngine();
// setting up file resource loader
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,
templateDir.getCanonicalPath());

This way, you have total control and know where to load the templates.
As for the output, it is as simple as:

OutputStreamWriter out = new
OutputStreamWriter(response.getOutputStream(), "UTF-8");
ve.mergeTemplate(viewName + ".html", "UTF-8", ctx, out);
if (flushOutput)
{
	out.flush();
}

This is pretty much how I am using Velocity right now. Hope it helps.


Jian
http://www.JiansNet.com
Useful Info on Living In USA, Powered By Velocity

On Sat, May 26, 2012 at 9:13 AM, vanessa vanessa
<[email protected]> wrote:
> Hi all ,
>
> I'm using velocity in a plug-in projet.In the root of my plugin
> i put a folder templates/template.vm. And i call the template
> velocity.getTemplate(template.vm) from my class.
> But the resource is not found i don't no why its directory isn't
> recognised.the template cannot be loaded.
>
> Every thing work fine in a java-Project.
>  I will appreciate any help.
> Thanks.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.