How to customize FreeMarker template by using Jar?

cancel
Showing results for 
Search instead for 
Did you mean: 
alekseybykov
Established Member II

How to customize FreeMarker template by using Jar?

Jump to solution

Some times ago, I used Alfresco 5.2 Community Edition. When I needed to develop some kind of customization, I used the Alfresco Maven SDK with three different Maven archetypes, it was:

  1. Alfresco Repository AMP;
  2. Alfresco Share AMP;
  3. Alfresco all-in-one (AIO).

By using this SDK I developed AMP files that overlaid on either the alfresco.war or share.war by using the module management tool.

Now I am using Alfresco 4.2.2 Enterprise Edition and the problem is that all the customizations over the years have been performed directly on the servers in the exploded WAR's.

This approach is described here: 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 ...

And further:

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 ...

Thus, I can't use AMP-customizations(otherwise all previous developments will be deleted). As far as I know, I can use an alternative- JAR-customization.

As described here: Packaging And Deploying Extensions

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 ...

However, I can not take advantage of this approach either. For example, I need to override the FreeMarker template:

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

I create the appropriate directory structure in IDE, change the template in some way, and build the Jar file. Then I put it in tomcat7/shared/lib (I also placed it in tomcat7/webapps/share/WEB-INF/lib, but also without success) and restart the application server.

After restarting, I don't see my changes - the template remained the same. Moreover, if I try to add another template to the same directory (.../service-note/...), a new template there does not appear.

In my Tomcat installation shared classloader is configured properly.

What am I doing wrong? How to override static resources by using JAR?

I would be very grateful for the information. Thanks to all.

1 Solution

Accepted Solutions
alekseybykov
Established Member II

Re: How to override static resources by using JAR?

Jump to solution

It is necessary to use the SurfBug debugging tool to identify the template file (Template Type property).

Then develop the Spring Surf extension module - "are the preferred way of customizing many of the Alfresco Share user interface features" - and pack it into the Jar. Then I should use the Module deployment which is available through the web- script at:

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

I can customize the FTL file as follows:

  • Place the new content before/ after the certain @region;
  • Replace the content of the certain @region with the new content;
  • Remove the certain @region completely.

See also:

Regards,
Aleksey Bykov

3 Replies
Highlighted
krutik_jayswal
Senior Member II

Re: How to override static resources by using JAR?

Jump to solution

First of all,It is very much important to retain the changes which we do in alfresco.As you do not track of those changes, I recommend you to first configure the amp/jar/all-in-one project to have the those changes in maven project and configure git/svn for it.

For this you can compare folder structure of alfresco with fresh installation of your specific alfresco version.This is very important task and you must do it.No matter how much time it takes.

Regarding your question : As far as i know, on version before 4.2 or 5 , you can not deploy static resource using jar.You need to have the updated version of alfresco to use static resource in jar.

Hope this help.

alekseybykov
Established Member II

Re: How to override static resources by using JAR?

Jump to solution

Hi, Krutik Jayswal.

Thank you very much for your answer.

I found this wonderful documentation, but has not yet been able to experiment due to technical works on the servers. I think this documentation solves my problem - what do you think about it?..

Why should I upgrade my version of Alfresco?... If I do it, I'll lose customizations, which was doing before me for several years. I just need to find the right way to support what I have now and the right way to make new customizations in my environment according to customer's requirements.

In any case, thanks for your reply, I appreciate it.

Regards,
Aleksey Bykov

alekseybykov
Established Member II

Re: How to override static resources by using JAR?

Jump to solution

It is necessary to use the SurfBug debugging tool to identify the template file (Template Type property).

Then develop the Spring Surf extension module - "are the preferred way of customizing many of the Alfresco Share user interface features" - and pack it into the Jar. Then I should use the Module deployment which is available through the web- script at:

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

I can customize the FTL file as follows:

  • Place the new content before/ after the certain @region;
  • Replace the content of the certain @region with the new content;
  • Remove the certain @region completely.

See also:

Regards,
Aleksey Bykov