FMGenerator integrates FreeMarker templates into Eclipse by providing a builder plugin.
To install the plugin, simply download the plugin jar file and place it in the Eclipse plugins directory, then restart Eclipse.
To enable FMGenerator for a project in Eclipse, right-click on the project and select "Configure"->"FreeMarker Nature".
With FMGenerator enabled, files that end in ".fmg" will be processed by FreeMarker to generate target files. The name of the target file and the file content are determined by macros that must be defined in the FreeMarker template. These macros are fmg_path
and fmg_content
.
For example, if the Eclipse project contains a file named sample.fmg
which contains the following text, it will generate the file HelloWorld.java
in the src folder at the root of the Eclipse project.
<#macro fmg_path>src/HelloWorld.java</#macro>
<#macro fmg_content>
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
</#macro>
In Eclipse, this sample template would look like:
The resulting, generated code: