Hmm.  What Java version are you using?  VelocityTools 2 requires JDK
1.5+  If you need a JDK 1.4 version, you should use VelocityTools 1.4,
in which the WebappResourceLoader was named
org.apache.velocity.tools.view.servlet.WebappLoader

On Tue, Dec 30, 2008 at 9:52 PM, Chachad, Ketan
<[email protected]> wrote:
> Hi Nathan,
>
> As suggested by you I tried using WebappResourceLoader.
> For the same I downloaded velocity-tools-2.0-beta1.jar and configured
> the jar in my server classpath.
> I am using velocity-1.6.1.jar and velocity-1.6.1-dep.jar for the
> Velocity Engine.
> Now when I start the server I get the following error message:
>
> [12/31/08 11:11:11:518 IST] 744f744f ServletInstan E SRVE0100E: Did not
> realize  init() exception thrown by servlet velocity:
> javax.servlet.ServletException: LinkageError while defining class:
> org.apache.velocity.tools.view.WebappResourceLoader
> Could not be defined due to:
> (org/apache/velocity/tools/view/WebappResourceLoader) bad major version
> at offset=6
> This is often caused by having a class defined at multiple
> locations within the classloader hierarchy.  Other potential causes
> include compiling against an older or newer version of the class
> that has an incompatible method signature.
> Dumping the current context classloader hierarchy:
>    ==> indicates defining classloader
> ==>[0]
> ...
> ---Original exception---
> java.lang.UnsupportedClassVersionError:
> (org/apache/velocity/tools/view/WebappResourceLoader) bad major version
> at offset=6
>
> The server is starting even after this error. But I doubt if Velocity
> will work because of this error.
> Please let me know what could be the reason for this exception.
>
> Regards,
> Ketan K. Chachad | D: +91 22 67 33 34 63 | M: +91 98 19 17 02 71
>
> -----Original Message-----
> From: Nathan Bubna [mailto:[email protected]]
> Sent: Tuesday, December 30, 2008 11:40 PM
> To: Velocity Users List
> Subject: Re: ResourceNotFoundException thrown when getTemplate() called
>
> You need to use the WebappLoader from VelocityTools.  The
> FileResourceLoader is far too much trouble to get working in a web
> application.
>
> Be sure to read:
> http://velocity.apache.org/engine/devel/webapps.html
>
> On Tue, Dec 30, 2008 at 1:46 AM, Chachad, Ketan
> <[email protected]> wrote:
>> 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
>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to