Primitive Wrapper for Apache Velocity
VelocityPage is a convenient builder/wrapper around Apache Velocity:
import com.jcabi.velocity.VelocityPage; public class Main { public static void main(String[] args) { String text = new VelocityPage("/com/foo/template.vm") .set("name", "John Doe") .set("file", file) .set("document", doc) .toString(); } }
The only argument of the constructor should be an absolute path of a classpath resource that contains a Velocity template. Be aware that an absolute resource path always starts with a slash.
The only dependency you need is (you can also download jcabi-velocity-0.8.jar and add it to the classpath):
<dependency> <groupId>com.jcabi</groupId> <artifactId>jcabi-velocity</artifactId> <version>0.8</version> </dependency>
Cutting Edge Version
If you want to use current version of the product, you can do it with this configuration in your pom.xml:
<repositories> <repository> <id>oss.sonatype.org</id> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.jcabi</groupId> <artifactId>jcabi-velocity</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies>