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