Freemarker Development-Getting Started

Source: Internet
Author: User

1. Download Freemarker.jar

Can be downloaded to the official website: http://freemarker.org/.

The downloaded freemarker-2.3.23.tar.gz 3.2 MB contains Freemarker.jar, source code, and API documentation.

2. Create Java Project

1) Create a new Lib directory in the project, put the Freemarker.jar into the Lib directory, and "Add to build Path".

2) Create a new templates directory under SRC to store the template file. Create a new Example.flt file in the templates directory with the following contents:

${example}

3) Create a new test class freemarkertest under SRC. The contents are as follows:

1  Public classFreemarkertest {2      Public Static voidMain (string[] args)throwsIOException,3 templateexception {4Configuration conf =NewConfiguration ();5         //set the directory where template files are loaded6Conf.setdirectoryfortemplateloading (NewFile ("Src/templates"));7         //set How templates retrieve the data model8Conf.setobjectwrapper (NewDefaultobjectwrapper ());9         //Create, parse, and cache templatesTenTemplate template = Conf.gettemplate ("Example.flt"); One         //Preparing Data Amap<string, object> root =NewHashmap<string, object>(); -Root.put ("Example", "Hello world!"); -         //merging data with a template theTemplate.process (Root,NewOutputStreamWriter (System.out)); -     } -}

4) Run Freemarkertest, output as follows:

Hello world!

3. Associating Freemarker source code to eclipse

Extract the source directory from the freemarker-2.3.23.tar.gz and link to eclipse for easy viewing of the source code in development.

Freemarker Development-Getting Started

Related Article

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.