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
The Jamon primary repository is athttp://maven.jamon.org/.
All Jamon artifacts (aside from Eclipse plugins) are deployed there.
Generally, there are three sections of your pom.xml that will need
to be configured.
1. Plugin repository
<pluginRepositories>
...
<pluginRepository>
<id>jamon plugin</id>
<name>jamon plugin</name>
<url>http://maven.jamon.org/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
...
</pluginRepositories>
2. General dependency repository
<repositories>
...
<repository>
<id>jamon</id>
<name>jamon primary repository</name>
<layout>default</layout>
<url>http://maven.jamon.org</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
...
</repositories>
3. Compile and runtime dependency
<dependencies>
<dependency>
<dependency>
<group>org.jamon</group>
<artifactId>jamon-runtime</artifactId>
<version>2.3.0</version>
</dependency>
</dependency>
</dependencies>
4. Hook into project build lifecycle
<build>
<plugins>
...
<plugin>
<groupId>org.jamon</groupId>
<artifactId>jamon-maven-plugin</artifactId>
<version>2.3.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>translate</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
5. (Optional) Hook into Eclipse
Yes, this is far from optimal. Add the following to theplugins 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 forjamon.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.0</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>