Description #
Velocity is a Java-based templating language designed to generate web pages, email content, source code, or configuration files from dynamic data. It emphasizes a clean separation of logic and presentation.
History #
Velocity was developed by the Apache Software Foundation and released in 2001 as part of the Jakarta project. It became widely used in Java web apps, particularly with frameworks like Apache Turbine, Spring, and Struts.
Hello World Code #
<h1>$message</h1>
With context in Java:
VelocityContext context = new VelocityContext();
context.put("message", "Hello, World!");
template.merge(context, writer);
How to Run #
Option 1: Online
There is no official online Velocity runner, but you can test in full Java REPLs:
https://www.jdoodle.com/ (with custom Velocity lib)
Option 2: Local
Add to Maven project:
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.3</version>
</dependency>
Java usage:
Velocity.init();
Template template = Velocity.getTemplate("hello.vm");
VelocityContext context = new VelocityContext();
context.put("message", "Hello, World!");
template.merge(context, new OutputStreamWriter(System.out));
Key Concepts #
- Uses
$variable
for output #foreach
,#if
,#include
for control flow- Templates typically use
.vm
extension - Java-first integration for web, email, or static generation
- Simple, readable syntax
- Precompilation not required
- Supports macros for reusable logic
- Widely used in legacy enterprise apps
- Good performance for large template sets
- Apache-licensed and actively maintained
Try It Online #
https://www.jdoodle.com/ (Velocity requires setup in Java projects)
Fun Facts #
- Velocity inspired the creation of other template engines like FreeMarker.
- Despite its age, it’s still used in enterprise systems like Jira and Confluence.
- Velocity’s
.vm
files are still found in many open-source CMS and ERP systems.
Resources #
Official site
Docs or tutorial
GitHub or interpreter
Community or learning resources