FreeMarker

Java-based template engine


title: "FreeMarker" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["java-enterprise-platform", "template-engines"] description: "Java-based template engine" topic_path: "general/java-enterprise-platform" source: "https://en.wikipedia.org/wiki/FreeMarker" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0

::summary Java-based template engine ::

::data[format=table title="Infobox Software"]

FieldValue
nameApache FreeMarker
logo[[File:Apache_FreeMarker_Logo.svg
developerJonathan Revusky, Attila Szegedi, Dániel Dékány, and others
released2000
latest release version2.3.34
latest release date
operating systemCross-platform
programming languageJava
genreTemplate Engine
licenseApache License 2.0
website
repo
::

| name = Apache FreeMarker | logo = [[File:Apache_FreeMarker_Logo.svg|250px|FreeMarker Logo.png]] | screenshot = | caption = | developer = Jonathan Revusky, Attila Szegedi, Dániel Dékány, and others | released = 2000 | latest release version = 2.3.34 | latest release date = | operating system = Cross-platform | programming language = Java | genre = Template Engine | license = Apache License 2.0 | website = |repo= Apache FreeMarker is a free Java-based template engine, originally focusing on dynamic web page generation with MVC software architecture. It can now generate text based on templates and changing data. It has no dependency on servlets or HTTP or HTML.

It is often used for generating source code, configuration files or e-mails.

History

FreeMarker had a somewhat hectic history until about 2004, caused by paradigm shifts and other significant changes on multiple occasions. FreeMarker 1 (now known as FreeMarker Classic, a separate project) was originally written by Benjamin Geer and Mike Bayer. From 2002, the new project lead was Jonathan Revusky, who released FreeMarker 2, which started a sequence of several substantial changes. The main goal of the changes was to make the template language more strict, i.e., to detect as many of the typos and other typical mistakes as possible. Also, automatic object wrapping was introduced, along with gradual advancement of the type system of the template language. The language has gained many power-user features, such as more powerful macro programming capabilities and namespaces. The language has reached a quite settled state with version 2.3, released in 2004 Q3. As of 2022, the product has remained backward compatible. No significant backward incompatible changes are expected in the FreeMarker 2 series in the future.

In late 2015, FreeMarker was granted to the Apache Software Foundation, where it has entered the Apache Incubator, and in 2018-03-21 it has become a fully accepted Apache project.

Example

The following template:

::code[lang=html]

Hello ${name}! You have the following messages: <#list messages as m>

${m.from}: ${m.body}

::

processed by FreeMarker will produce something like:

::code[lang=html]

Hello Joe! You have the following messages:

Tim: Please don't forget to bring the conference papers!

Cindy: Can you give me a visit this afternoon?

Richard: Don't forget the papers this time!

::

Variables like "name" and "messages" are coming from outside the template, and thus the template author has to deal with the presentation issues only. The template remains the same regardless if these variables are coming from a database or from a cookie or calculated in whatever other ways. Also the exact Java API (and hence the class) of the values can be hidden in FreeMarker using a technique called object wrapping. For example, "messages" seems to be a list or array of JavaBeans that have "from" and "body" properties, but it might as well be something very different, and the template is not affected (as long as a proper object wrapper is used).

References

References

  1. Cardoza, Christina. (2017-03-27). "Apache Calcite, FreeMarker, Gora, Phoenix, and Solr updated".
  2. Mittapalli, Jishnu Saurav. (2021). "Survey on Template Engines in Java". EDP Sciences.

::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::

java-enterprise-platformtemplate-engines