Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set properly the loader path of velocity

i would like that my velocityengine look for templates from a designed path. i did this :

<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
 <property name="velocityProperties">
   <value>
     resource.loader=class
     class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
     class.resource.loader.resourceLoaderPath=/mytemplates
   </value>
 </property>

but is still looking for templates in the classes folder. any idea?

like image 817
storm_buster Avatar asked Mar 17 '11 17:03

storm_buster


People also ask

Where is Velocity properties?

Configuring Velocity There is a set of default values contained in Velocity's jar, found in org/apache/velocity/runtime/defaults/velocity. properties, that Velocity uses as its configuration baseline.

What is Velocity template?

Velocity is a server-side template language used by Confluence to render page content. Velocity allows Java objects to be called alongside standard HTML. If you are are writing a user macro or developing a plugin you may need to modify Velocity content.

How does Apache Velocity work?

Velocity separates Java code from the web pages, making the web site more maintainable over the long run and providing a viable alternative to Java Server Pages (JSPs) or PHP. Velocity can be used to generate web pages, SQL, PostScript and other output from templates.


1 Answers

As illustrated in the spring documentation, you could try the following:

<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
  <property name="velocityProperties">
    <props>
      <prop key="resource.loader">file</prop>
      <prop key="file.resource.loader.class">
        org.apache.velocity.runtime.resource.loader.FileResourceLoader
      </prop>
      <prop key="file.resource.loader.path">${webapp.root}/WEB-INF/velocity</prop>
      <prop key="file.resource.loader.cache">false</prop>
    </props>
  </property>
</bean>

Alternately, you could declare these properties in a velocity.properties and specify that

<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
  <property name="configLocation" value="/WEB-INF/velocity.properties"/>
</bean>
like image 70
Raghuram Avatar answered Oct 01 '22 13:10

Raghuram