Apache FreeMarkerâ„¢ {version}

Build status

For the latest version or to report bugs visit: https://freemarker.apache.org/

Regarding pull requests on Github

By sending a pull request you grant the Apache Software Foundation sufficient rights to use and release the submitted work under the Apache license. You grant the same rights (copyright license, patent license, etc.) to the Apache Software Foundation as if you have signed a Contributor License Agreement. For contributions that are judged to be non-trivial, you will be asked to actually signing a Contributor License Agreement.

What is Apache FreeMarkerâ„¢?

Apache FreeMarkerâ„¢ is a "template engine"; a generic tool to generate text output (anything from HTML to auto generated source code) based on templates. It's a Java package, a class library for Java programmers. It's not an application for end-users in itself, but something that programmers can embed into their products. FreeMarker is designed to be practical for the generation of HTML Web pages, particularly by servlet-based applications following the MVC (Model View Controller) pattern.

Licensing

FreeMarker is licensed under the Apache License, Version 2.0.

See the LICENSE file for more details!

Documentation

Online: https://freemarker.apache.org/docs/

Offline: The full documentation is available in the binary distribution in the documentation/index.html directory.

Installing

If you are using Maven, just add this dependency:

  <!--
  Attention: Be sure nothing pulls in an old dependency with groupId
  "freemarker" (without the "org."), because then you will end up with
  two freemarker.jar-s and unpredictable behavior on runtime!
  -->
  <dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker-gae</artifactId>
    <version>{version}</version>
  </dependency>

Otherwise, simply copy freemarker.jar to a location where your Java application's ClassLoader will find it. For example, if you are using FreeMarker in a web application, you probably want to put freemarker.jar into the WEB-INF/lib directory of your web application.

FreeMarker has no required dependencies. It has several optional dependencies, but usually you don't have to deal with them, because if you are using an optional feature that's certainly because your application already uses the related library.

Attention: If you upgrade to OpenJDK 9 or later, and you are using XPath queries in templates, you will need to add Apache Xalan as a dependency, as freemarker.ext.dom can't use the XPath support included in OpenJDK anymore. It's not needed on Oracle Java 9, or if FreeMarker is configured to use Jaxen for XPath.

The minimum required Java version is currently Java SE 8. (The presence of a later version is detected on runtime and utilized by FreeMarker automatically.)

Change log

Online (for stable releases only): https://freemarker.apache.org/docs/app_versions.html

Offline: In the binary release, open documentation/index.html, and you will find the link.

Building FreeMarker

If you haven't yet, download the source release, or checkout FreeMarker from the source code repository. See repository locations here: https://freemarker.apache.org/sourcecode.html

You need JDK 8, JDK 16, and JDK 17 (only for some tests) to be installed (and visible to Gradle). That's because different parts of the source code target different Java versions, and Gradle requires the exact JDK version (not higher) for each.

Be sure that your default Java version (which Gradle should use automatically) is at least 17!

If you are building from the official source release (not from source that you got from Git), gradle/wrapper/gradle-wrapper.jar is missing from that, and you have to add it yourself! You can download it from GitHub source code page! (Or, use your own Gradle installation instead of gradlew.)

To build freemarker.jar, just issue ./gradlew jar (gradlew.bat jar on Windows) in the project root directory, and it should download all dependencies automatically, and build freemarker.jar.

To run all JUnit tests and some other checks, issue ./gradlew check. (Avoid the test task, as that will only run the tests of the core source set.)

To generate documentation, issue ./gradlew javadoc and ./gradlew manualOffline.

To build the distribution artifacts (the tgz-s that people can download), run ./gradlew build. However, for a stable (non-SNAPSHOT) version number, you must set up signing, or disable that verification with freemarker.allowUnsignedReleaseBuild=true; see gradle.properties in this project for those!

Reproducible builds: If the resulting freemarker.jar is not identical with the official jar, see the build environment in the .buildinfo file packed into the official source distribution, and also into the Maven "sources" artifact! At least with identical Java versions, the resulting freemarker.jar meant to match exactly.

Note on trying things out with an ad-hoc class that has main method: Don't do that, instead write it as a JUnit test. FreeMarker needs to be loaded from freemarker.jar that contains the META-INF/versions directory (as per JEP 238, Multi-Release JAR Files). If you run a test, Gradle ensures that you have an up-to-date freemarker.jar, and that it's in the classpath. Without that, FreeMarker will behave as if you are on a lower Java version.

To see how the project would be deployed to Maven Central, issue ./gradlew publishAllPublicationsToLocalRepository, and check the build/local-deployment directory.

To publish to the Apache Maven Repository (from where you can also promote releases to the Maven Central Repository) issue .\gradlew publish. Note that for this the following Gradle properties must be properly set (in gradle.properties, or pass them via -P<name>=<value> arguments): freemarker.signMethod, freemarker.deploy.apache.user, freemarker.deploy.apache.password.

IDE setup

IntelliJ IDEA

Originally done on IntelliJ IDEA Community 2023.3.2:

Eclipse

This section wasn't updated long ago. But you should import the project as any other Gradle project. After that, it's recommended to set these preferences (based on Eclipse Mars):

Join libs.tech

...and unlock some superpowers

GitHub

We won't share your data with anyone else.