Okygraph
Compile-time Java template engine: two symbols of syntax, no runtime dependencies, templates become plain Java classes.
ὠκύγραφος — Greek for swift writer
A compile-time Java template engine. 361 lines of plugin code. Zero lines of runtime you need to understand. No runtime dependencies. No custom syntax to learn. No ViewResolver configuration. Just Java with HTML inside.
Two Concepts
` switches between Java and HTML
{} outputs a Java expression
That's the entire syntax — including conditions, loops, and try/catch:
protected void render() {`
<p>Greetings {user.name}!</p>
`if (user.isActive()) {`
<p>User is active</p>
`} else {`
<p>User is inactive</p>
`}`
<h3>Hobbies of {user.name}:</h3>
<ul>
`for (var hobby : user.getHobbies()) {`
<li>{hobby}</li>
`}`
</ul>
`try {`
<img src="{attr(user.getAvatar())}">
`} catch (AppException e) {`
<img src="/img/defaultAvatar.png">
`}`
`}
try/catch works in templates because it is just Java: output written inside a failed try block is discarded.
To print a literal backtick or { in HTML, escape it with a backslash: \` and \{. Other backslashes are literal.
An expression {expr} may continue on the following lines, for example a chain of calls.
Expressions inside {expr} must not contain nested Java braces. Array initializers, block lambdas, anonymous classes and switch expressions with braces are intentionally unsupported here; compute such values in the model and reference the result in the template. Braces inside Java string or character literals are allowed, for example {"{}"}.
Escaping
{expr} escapes &, < and >, which is right for text. Inside a quoted attribute write {attr(expr)}: it also escapes " and '. {raw(expr)} prints unescaped HTML. Okygraph does not guess the context, so choosing attr is the template author's job. raw and attr write their output immediately, so each must be the whole expression: {raw(x)}, not {raw(x) + y}. There is no JS or CSS escaping yet: keep scripts and styles in their own files.
The Maven plugin transpiles this to pure Java at compile time. The result is a regular Java class — fully type-safe, debuggable, refactorable in any IDE, optimizable by the JIT.
Setup
<plugin>
<groupId>dev.okygraph</groupId>
<artifactId>okygraph-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<framework>SPRING</framework> <!-- SPRING | STANDALONE -->
<baseClassPackage>com.example.views</baseClassPackage>
</configuration>
<executions>
<execution>
<goals>
<goal>transpile</goal>
</goals>
</execution>
</executions>
</plugin>
Not on Maven Central yet. Install the plugin locally first:
cd okygraph-maven-plugin && mvn install.
Run mvn compile. The plugin transpiles .oky files found under src/main/java to regular .java files in target/generated-sources and adds that directory to the compile sources. No Spring Boot starter required — with SPRING the base class OkyTemplate implements org.springframework.web.servlet.View directly.
On the first build the plugin also writes the base class OkyTemplate.java into baseClassPackage under src/main/java (baseClassOutputDirectory). It never overwrites an existing file, so you can adapt it; delete it to regenerate. SPRING and STANDALONE have a base class template so far. STANDALONE needs no framework at all: new HomeView(model).render(writer) renders into any java.io.Writer and uses it as it is.
Why
Every Java template engine adds a runtime layer: expression evaluation, caching, view resolution, framework integration. Okygraph removes all of it.
Render time of the same two pages (a login form and a food page with about 90 table rows, shared layout, same model for every engine; JMH, 3 forks, one thread):
| Engine | Login page | Food page | Extra runtime jars in a Spring Boot app |
|---|---|---|---|
| Okygraph | 1.5 µs | 34 µs | 0 |
| JStachio 1.3.7 | 1.6 µs | 57 µs | 5 (with its Spring module) |
| JTE 3.2.5 | 2.0 µs | 53 µs | 5 (with its Spring starter) |
| mustache.java 0.9.14 | 4.4 µs | 165 µs | 1 |
| Rocker 2.4.0 | 5.3 µs | 159 µs | 1 |
| Pebble 4.1.2 | 6.5 µs | 273 µs | 4 |
| FreeMarker 2.3.35 | 9.0 µs | 293 µs | 3 |
| Handlebars.java 4.5.8 | 22 µs | 919 µs | 9 |
| Thymeleaf 3.1 | 80 µs | 2,062 µs | 5 |
Served over HTTP by Spring Boot (Tomcat, building the model included), the gap shrinks: on the food page Okygraph, JStachio and JTE are within the run-to-run variation of each other, Thymeleaf serves about a seventh as many requests. The first request after startup took 56 ms with Okygraph, 83 ms with JTE, 750 ms with Thymeleaf and 1.5 s with JSP (one start each). Okygraph needs no view resolver and no adapter: the generated template is the Spring View.
These are first runs on a development machine (WSL2), good for the order, not for exact figures; measurements on dedicated machines will follow. The benchmark, with every engine's templates and an equivalence test that checks that all engines produce the same page, lives in its own repository.
Features
- Full Java inside templates — conditions, loops, try/catch, method calls, lambdas
- Framework-neutral design —
<framework>selects the generated base class;SPRINGandSTANDALONEexist so far - No runtime template engine — templates are transpiled to Java source at compile time
- Zero dependencies — the generated code depends only on what you choose
- IDE support — refactoring, go-to-definition, and debugging work as expected
Philosophy
The goal was to find the minimum surface area for a template engine and remove everything else. ~360 lines. Nothing left to remove.