如何使用 Jar 自定义 FreeMarker 模板?

How to customize FreeMarker template by using Jar?

前段时间,我用过Alfresco 5.2 Community Edition。当我需要开发某种定制时,我使用了 Alfresco Maven SDK with three different Maven archetypes,它是:

通过使用此 SDK,我开发了 AMP files,它通过使用模块管理工具覆盖在 alfresco.warshare.war 上。

现在我用的是Alfresco 4.2.2 Enterprise Edition,问题是多年来所有的定制都是直接在exploded WAR的服务器上进行的。

这里描述了这种方法:Packaging Approaches

Unpackaged Files or ZIP

Many development environments employ a build process that can execute a script to move unpackaged modified files from source control into the web application's exploded WAR file. Ant, bash, or some scripting language can all be good ways to do this ...

Moving unpackaged files has the advantage of being quick and easy to understand ...

还有:

Deployment Locations

One solution is to use a permanently exploded deployment (instead of deploying an Alfresco WAR file under /webapps). Create a directory called alfresco under the webapps directory and extract the contents of alfresco.war into it. Then copy your files to ../webapps/alfresco/WEB-INF/ and restart Tomcat ...

因此,我不能使用 AMP 定制(否则所有以前的开发都将被删除)。据我所知,我可以使用替代方案——JAR 定制。

如同一文档中所述:

JAR

As of v3.4, the Share web application supports overrides that are packaged as JAR files. This allows multiple customizations to be isolated from each other, and order of selection can be predicted. Static files such as JavaScript, CSS, or image files that would normally be placed in the web root of the Share application can also be packaged into these JARs ...

While it's possible to avoid the overwriting problem (at least in Tomcat) by placing these JAR files in tomcat/shared/lib ...

但是,我也无法利用这种方法。例如,我需要覆盖 FreeMarker 模板:

/opt/tomcat7/webapps/share/WEB-INF/classes/alfresco/web-extension/site-webscripts/components/form/service-note/service-note-order-things.ftl

我在 IDE 中创建适当的目录结构,以某种方式更改模板,然后构建 Jar 文件。然后我把它放在tomcat7/shared/lib中(我也把它放在tomcat7/webapps/share/WEB-INF/lib中,但也没有成功)并重新启动应用程序服务器。

重新启动后,我没有看到我的更改 - 模板保持不变。此外,如果我尝试将另一个模板添加到同一目录 (.../service-note/...),则不会出现新模板。

在我的 Tomcat 安装中,共享类加载器配置正确。

我做错了什么?如何使用JAR覆盖静态资源?

如果能提供信息,我将不胜感激。感谢大家。

需要使用SurfBug debugging tool来识别模板文件(Template Type 属性)。

然后开发 Spring Surf extension module - "are the preferred way of customizing many of the Alfresco Share user interface features" - 并将其打包到 Jar 中。 然后我应该使用可通过网络获得的 Module deployment 脚本位于:

http://host:port/share/service/modules/deploy

FTL可以自定义如下:

  • 将新内容放在@region之前/之后;
  • 将某@region的内容替换为新的内容;
  • 完全删除某些@region

在文件系统中,我们将拥有相同的未修改模板,因为 SpringSurf 写入内存模型,然后允许扩展在模型刷新到输出流之前操作该模型。

另请参阅: