最近的项目是SSH,View层采用Freemarker,但是遇到了一个很大问题,每次修改完ftl文件,都要重新启动tomcat才可以看到所修改的内容,不但麻烦,而且浪费时间,特别怀念jsp,后来在网上查找解决办法,原来只是一个配置项的问题,对直freemarker的了解又加深了一步,原理及修改办法如下(以下部分为转载^_^):
一般来讲,模版文件改动不会很频繁,在一个流量非常大的网站中,如果频繁的读取模版文件对系统的负担还是很重的,因此 FreeMarker 通过将模版文件的内容进行缓存,来降低模版文件读取的频次,降低系统的负载。
当处理某个模版时,FreeMarker 直接从缓存中返回对应的 Template 对象,并有一个默认的机制来保证该模版对象是跟模版文件同步的
template_update_delay 用来指定更新模版文件的间隔时间,相当于多长时间检测一下是否有必要重新加载模版文件,0 表示每次都重新加载,否则为多少毫秒钟检测一下模版是否更改。
freemarker.properties内容:
template_update_delay=0
locale=zh_CN
default_encoding=utf-8
number_format=#
date_format=yyyy-MM-dd
time_format=HH:mm:Ss
datetime_format=yyyy-MM-dd HH:mm:Ss
红色为关键一行。
Publishing failed with multiple errors
Resource is out of sync with the file system: '/StrutsFileUpload/WebContent/WEB-INF/lib/commons-fileupload-1.2.1.jar'. Resource is out of sync with the file system: '/StrutsFileUpload/WebContent/WEB-INF/lib/commons-io-1.3.2.jar'. Resource is out of sync with the file system: '/StrutsFileUpload/WebContent/WEB-INF/lib/freemarker-2.3.15.jar'. Resource is out of sync with the file system: '/StrutsFileUpload/WebContent/WEB-INF/lib/ognl-2.7.3.jar'. Resource is out of sync with the file system: '/StrutsFileUpload/WebContent/WEB-INF/lib/struts2-core-2.1.8.1.jar'. Resource is out of sync with the file system: '/StrutsFileUpload/WebContent/WEB-INF/lib/xwork-core-2.1.6.jar'. |
这是文件系统不同步的问题,是因为在eclipse之外对工程中的resource进行修改引起的;但是,有时没有在eclipse之外进行修改,也会报类似的错误。
解决办法:需要手动刷新一下资源管理器。
(1)在eclipse中,工程目录右键,选择F5(refresh)
(2)设置eclipse自动刷新。
通过Window->Preferences->General->Workspace,选中Refresh automatically。