FreeMarker development-getting started with freemarker Development

Source: Internet
Author: User

FreeMarker development-getting started with freemarker Development

1. Download freemarker. jar

Download it from 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 a Java Project

1) create a lib directory in the project, Add freemarker. jar to the lib directory, and "Add to build path ".

2) create a new templates directory under src to store template files. Create the example. flt file in the templates directory. The content is as follows:

${example}

3) create a test class FreeMarkerTest under src. The content is as follows:

1 public class FreeMarkerTest {2 public static void main (String [] args) throws IOException, 3 TemplateException {4 Configuration conf = new Configuration (); 5 // set the directory 6 conf for loading the template file. setDirectoryForTemplateLoading (new File ("src/templates"); 7 // set the template to retrieve the data model in 8 conf. setObjectWrapper (new DefaultObjectWrapper (); 9 // create, parse the Template, and Cache 10 template Template = conf. getTemplate ("example. flt "); 11 // prepare the data 12 Map < String, Object> root = new HashMap <String, Object> (); 13 root. put ("example", "Hello World! "); 14 // Merge data with the template 15 template. process (root, new OutputStreamWriter (System. out); 16} 17}

4) Run FreeMarkerTest and the output is as follows:

Hello World!

3. Associate FreeMarker source code with eclipse

Extract the source directory from freemarker-2.3.23.tar.gz and associate it with eclipse to view the source code in development.

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.