我正在使用Liferay开发我的应用程序,并希望使用freemarker开发模板。
我只是测试了freemarker。 当我部署我的应用程序时,它说无法找到模板。 我知道模板文件应该在src文件夹中。 所以我在docroot.WEB-INF / src文件夹中创建了helloworld.ftl,并在代码中尝试使用语句访问它
Configuration cfg = new Configuration();
Template template = cfg.getTemplate("src/helloworld.ftl");
错误如下:
java.io.FileNotFoundException: Template src/helloworld.ftl not found.
我应该如何提供文件夹的路径?
答案 0 :(得分:0)
您需要获取portlet的PortletContext
,并使用getRealPath
获取文件的实际路径:
String realPath = portletContext.getRealPath("WEB-INF/src/helloworld.ftl");
Template template = cfg.getTemplate(realPath);
显然,你真的想要“WEB-INF / src”的路径,你可以将路径附加到特定的FTL文件。
答案 1 :(得分:0)
嘿我弄清楚问题是什么。在这里我会分享它。 在获取模板之前我没有加载模板:)