Overview
To make use of Jamon:- Create your templates.
- Run the template processor on the templates, either via the command line or the Jamon Ant task to generate Java source files corresponding to the templates.
- In your "regular" Java source files, reference templates like any other class.
- Include generated files in your build process.
- If you would like changes made to the template sources to be automatically reflected in the running application at runtime, create a RecompilingTemplateManager and pass it to TemplateManagerSource.setTemplateManager().
Example - Quick Start Mini-Tutorial
The source files mentioned in this tutorial are available individually where first referenced, or bundled in a zip file.
NOTE: If you have a Java Runtime (JRE) installed in addition
to a Software Development Kit (SDK), be sure that the binaries
(i.e. java, javac, etc) of the SDK come first in your
PATH.
-
Create a Jamon template QsTemp.jamon:
<%args> java.util.Date date; String [] s; </%args> Hello, world on <% date %>. The arguments are: <%java int l = s.length; %> <%for int i = 0; i < l; ++i %> <% s[i] %> </%for>
-
Create a java file JamonQs.java:
import java.io.OutputStreamWriter; import java.io.IOException; import java.util.Date; public class JamonQs { public static void main(String[] argv) throws IOException { QsTemp template = new QsTemp(); template.render(new OutputStreamWriter(System.out), new Date(0),argv); } }
-
Set your classpath:
Windows C:\JAMONTMP> SET CLASSPATH=.;\path\to\jamon-runtime.jar;\path\to\jamon-api.jar;\path\to\jamon-processor.jar Unix (sh, bash, zsh, ksh) $ export CLASSPATH=.:/path/to/jamon-runtime.jar:/path/to/jamon-api.jar:/path/to/jamon-processor.jar Unix (csh, tcsh) % setenv CLASSPATH=.:/path/to/jamon-runtime.jar:/path/to/jamon-api.jar:/path/to/jamon-processor.jar -
Process the template:
java org.jamon.compiler.TemplateProcessor --destDir=. QsTemp
-
Compile everything:
javac JamonQs.java QsTemp*.java
-
Run it:
java JamonQs one two three
-
You should see:
Hello, world on Wed Dec 31 19:00:00 EST 1969. The arguments are: one two three