Accessing arbitrary classes in Velocity Templates

Occasionally, I’ve found it necessary to use Java classes that are available in the libraries that Rhythmyx is using, but aren’t exposed in the $sys or $tools variables. In my case, I needed to create a java.lang.StringBuffer object. Here’s what I did:

#set( $buffer = $sys.getClass().forName('java.lang.StringBuffer').newInstance() )

You can use variations of this code to do anything from loading a reference to a class, to invoking specific methods.

I’ve merged this functionality into AtcToolkit as $user.debug.