static { // Ensure that $undefinedvar will produce an exception rather than outputting $undefinedvar. velocityRuntimeInstance.setProperty(RuntimeConstants.RUNTIME_REFERENCES_STRICT, "true"); velocityRuntimeInstance.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, new NullLogChute()); velocityRuntimeInstance.setProperty( RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS, ResourceCacheImpl.class.getName()); // Setting ResourceCacheImpl is should not be necessary since that is the default value, but // ensures that Maven shading sees that Apache Commons classes referenced from ResourceCacheImpl // are indeed referenced and cannot be removed during minimization. // Disable any logging that Velocity might otherwise see fit to do. velocityRuntimeInstance.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new NullLogChute()); // Velocity likes its "managers", LogManager and ResourceManager, which it loads through the // context class loader. If that loader can see another copy of Velocity then that will lead // to hard-to-diagnose exceptions during initialization. Thread currentThread = Thread.currentThread(); ClassLoader oldContextLoader = currentThread.getContextClassLoader(); try { currentThread.setContextClassLoader(TemplateVars.class.getClassLoader()); velocityRuntimeInstance.init(); } finally { currentThread.setContextClassLoader(oldContextLoader); } }