Velocity method of reading template files

Source: Internet
Author: User

In Java EE application Development, the velocity template files are often packaged together in a jar file, but velocity's default behavior is to read the template file from the OS file system and use Fileresourceloader to read the template file.

If you want to get the template file from Classpath instead, adjust the velocity initialization parameters:
Velocityengine ve=new velocityengine ();
Optional value: "Class"-read from Classpath, "file"-read from the file system
Ve.setproperty ("Resource.loader", "class");
If the template is read from the file system, then the property value is Org.apache.velocity.runtime.resource.loader.FileResourceLoader
Ve.setproperty ("Class.resource.loader.class", " Org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader ");
Ve.init ();
Template t=ve.gettemplate ("/VMPATH/TEST.VM");

In addition, velocity defaults provide a variety of ways to read templates, listed below, which can refer to Javadoc in the release package:
Org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader
Org.apache.velocity.runtime.resource.loader.JarResourceLoader
Org.apache.velocity.runtime.resource.loader.StringResourceLoader
Org.apache.velocity.runtime.resource.loader.URLResourceLoader

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.