I had a similar problem while setting up while executing some parameters. I figured out this problem with a custom VelocityBuilder and an external velocity.properties file where you can put all the runtime properties. Here is the code:
public class BaseVelocityBuilder implements VelocityBuilder { private VelocityEngine engine; private Log logger = LogFactory.getLog(getClass()); @Autowired private WebApplicationContext webApplicationContext; public VelocityEngine engine() { if(engine == null) { engine = new VelocityEngine(); Properties properties = new Properties(); InputStream in = null; try { in = webApplicationContext.getServletContext().getResourceAsStream("/WEB-INF/velocity.properties"); properties.load(in); engine.init(properties); } catch (IOException e) { e.printStackTrace(); logger.error("Error loading velocity engine properties"); throw new ProgramException("Cannot load velocity engine properties"); } IOUtils.closeQuietly(in); } return engine; } }
See this line:
in = webApplicationContext.getServletContext().getResourceAsStream("/WEB-INF/velocity.properties"); properties.load(in); engine.init(properties);
So, I have a velocity.properties file in / WEB -INF, where I added some configuration:
resource.loader = webinf, class webinf.resource.loader.description = Framework Templates Resource Loader webinf.resource.loader.class = applica.framework.library.velocity.WEBINFResourceLoader webapp.resource.loader.class = org.apache.velocity.tools.view.servlet.WebappLoader webapp.resource.loader.path = file.resource.loader.description = Velocity File Resource Loader file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader file.resource.loader.path = class.resource.loader.description = Velocity Classpath Resource Loader class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader runtime.log='/pathYouWant/velocity.log'
At the end of your .xml application:
<bean class="applica.framework.library.velocity.BaseVelocityBuilder" />
Thus, you can have, for example, a different log file for different applications, and when you give war on production, sysadm can change properties due to the env configuration on the production server.
source share