Overview
Within a Java program, each Jamon template is represented as an instance of a class specific to that template. In order for your program to compile, Jamon templates need to be translated into Java source classes, and those generated Java sources need to be included in the build of your project.
Assumptions
- Jamon templates are located in the directory
tree named '
./src/templates
' - Java source files corresponding to Jamon
templates will be generated into the directory
'
./tsrc
'.
Building with Maven
Jamon releases are now mirrored on the primary Maven repository sites (http://repo1.maven.org/). All Jamon artifacts (aside from
Eclipse plugins) should be available there.
Generally, there are three sections of your pom.xml that will need
to be configured.
1. Compile and runtime dependency
<dependencies>
<dependency>
<dependency>
<groupId>org.jamon</groupId>
<artifactId>jamon-runtime</artifactId>
<version>2.3.0</version>
</dependency>
</dependency>
</dependencies>
2. Hook into project build lifecycle
<build>
<plugins>
...
<plugin>
<groupId>org.jamon</groupId>
<artifactId>jamon-maven-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>translate</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
3. (Optional) Hook into Eclipse
(Yes, this is far from optimal.)
Add the following to the plugins
section, ensuring
the templateSourceDir and templateOutputDir match your project:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<additionalProjectnatures>
<projectnature>org.jamon.project.jamonnature</projectnature>
</additionalProjectnatures>
<buildcommands>
<buildcommand>org.jamon.project.templateBuilder</buildcommand>
<buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand>
<buildcommand>org.jamon.project.markerUpdater</buildcommand>
</buildcommands>
<additionalConfig>
<file>
<name>.settings/org.jamon.prefs</name>
<content># now
eclipse.preferences.version=1
templateSourceDir=templates
templateOutputDir=tsrc
</content>
</file>
</additionalConfig>
</configuration>
</plugin>
Customizing the plugin
You can change the location where the plugin looks for template
sources and the locaiton where it generates Java files by
specifying the properties for jamon.template.src
and jamon.template.output
in each execution
section above. For example, to root your template sources at
src/main/jamon
and generate Java sources into
src/gen
, your execution section would look like:
<build>
<plugins>
...
<plugin>
<groupId>org.jamon</groupId>
<artifactId>jamon-maven-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>translate</goal>
</goals>
<configuration>
<templateSourceDir>src/main/jamon</templateSourceDir>
<templateOutputDir>src/gen</templateOutputDir>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>