How to #include a file from a Velocity template using ClasspathResourceLoader

醉酒当歌 提交于 2019-12-03 01:46:12

Re the sample code, the problem is solved by adding one more property to the Properties instance used to initialize the engine:

properties.setProperty(RuntimeConstants.EVENTHANDLER_INCLUDE, IncludeRelativePath.class.getName());

This allows to reference the path of the file to be included as a path relative to the folder where the including template is. So if both files are in the same folder then no path needs to be specified in the #include directive: just #include("MyInclude.vm").

I was also hoping to learn something about the obscure (to me) TEMPLATE_ROOT, like for ex. what it is, since it is surprisingly difficult for me to find this info documented anywhere. But whatever it is, at least in my case it corresponds to the root package of the Java project (the "default" package). This means that if I don't use the additional property mentioned above, then placing the file MyInclude.vm in the root package works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!