Hi,

 

I am trying to use Velocity templates in my project. I have a Struts
Action class that invokes a Command class which in turn invokes a Logic
class.

The job of the Logic class is to handle the main logic of the
functionality or use case.

 

I have designed Util classes that need to make use of Velocity templates
to generate required data.

I have added the following to the web deployment descriptor (web.xml)
file.

...

<servlet>

      <servlet-name>velocity</servlet-name>

 
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServle
t</servlet-class>

      <init-param>

            <param-name>org.apache.velocity.properties</param-name>

            <param-value>/WEB-INF/velocity.properties</param-value>

      </init-param>

      <load-on-startup>1</load-on-startup>

</servlet>

...

<servlet-mapping>

      <servlet-name>velocity</servlet-name>

      <url-pattern>*.vm</url-pattern>

</servlet-mapping>

...

 

The velocity.properties file has the below given contents

resource.loader=file

file.resource.loader.class=org.apache.velocity.runtime.resource.loader.F
ileResourceLoader

file.resource.loader.path=/WEB-INF/templates/

file.resource.loader.cache=false

file.resource.loader.modificationCheckInterval=0

 

velocimacro.library = /WEB-INF/VM_global_library.vm

velocimacro.permissions.allow.inline = true

velocimacro.permissions.allow.inline.to.replace.global = false

velocimacro.permissions.allow.inline.local.scope = false

velocimacro.context.localscope = false


Whenever I start the server, I get the following error messages with a
whole load of stack traces.

[12/30/08 13:14:18:105 IST] 744f744f WebGroup      I SRVE0180I: [supWeb]
[/sup] [Servlet.LOG]:  Velocity  [error] ResourceManager : unable to
find resource '/WEB-INF/VM_global_library.vm' in any resource loader.

[12/30/08 13:14:18:120 IST] 744f744f WebGroup      I SRVE0180I: [supWeb]
[/sup] [Servlet.LOG]:  Velocity  [error] Velocimacro : Velocimacro :
Error using VM library : /WEB-INF/VM_global_library.vm

[12/30/08 13:14:18:167 IST] 744f744f WebGroup      I SRVE0180I: [supWeb]
[/sup] [Servlet.LOG]:  Velocity  [error]
org.apache.velocity.exception.ResourceNotFoundException: Unable to find
resource '/WEB-INF/VM_global_library.vm'

 

But the server starts successfully. Now when the Util class is invoked.
It makes a call to the getTemplate() method of Velocity class.

And this time too I get a ResourceNotFoundException with the message
"Unable to find resource abcd.vm

 

The code written, in the Util class, for getting the templates is as
follows:

StringWriter sw = new StringWriter();

String path="/ABCD/abcd";

VelocityContext ctx = null;

try {

       Velocity.init();

       ctx = new VelocityContext();

       template = Velocity.getTemplate("abcd.vm");

       ctx.put("path", path);

       template.merge(ctx, sw);

       System.out.println(sw);

} catch (Exception ex) {

       System.out.println(ex);

       ex.printStackTrace();

}

 

I get a ResourceNotFoundException at line Velocity.getTemplate().

The template files have been placed in /WEB-INF/templates folder.

I am using Websphere 5.1 as application server.

 

Regards,

Ketan K. Chachad | Atos Origin India | Tower I - France |
[email protected] <mailto:[email protected]>  | D:
+91 22 67 33 34 63 | M: +91 98 19 17 02 71

 

Reply via email to