Friday, September 7, 2012

How to use Velocity in xPages

We are using velocity in our project for build some HTML fro some templates.

There was a problem with using it in the Java libraries. Look at this post to find problem description and solution.

Now we want to use velocity in the xPage context. There is also a little trouble:

at java.lang.SecurityManager.checkPermission(
at java.lang.Thread.getContextClassLoader(
at org.apache.velocity.util.ClassUtils.getClass(

This problem could be resolved  by adding next string in to the java.policy:

permission java.lang.RuntimePermission "getClassLoader";

We could not edit java.policy unfortunately. So we resolve it in the next way.

1. Download velocity source

2. Find place of error (at org.apache.velocity.util.ClassUtils.getClass(
ClassLoader loader = Thread.currentThread().getContextClassLoader();

3. Replace this string with the xPage classloader initialization:
ClassLoader cl =;

4. Add appropriate library for compile velocity source with this new class.  You will need
or similar

5. Compile new velocity jar from modified source.

Well done! You could upload velocity jar in to the WebContent\WEB-INF\lib and use it in the xPage context.

No comments: