Blogs

Blogs

OSGi Module Patching Guide

I wanted to share some testing that I have been doing in terms of patching OSGi modules and adding the patched modules to your own Liferay installations.  One of the many benefits to modularity is that it allows for these kinds of changes to be made without having to recompile the whole platform from scratch.

Update: This procedure has been updated to make use of a new feature in Liferay Portal 7 CE GA3 which allows updated modules to override the original module without modifying the original .lpkg file which is much simpler. For more details see the README.

Disclamer: This procedure is only meant for use by Liferay 7 CE.  Customers using Liferay DXP should continue to using the patching instructions provided in the offical documentation.

Overview

The example I would like to use is patching the JSP compiler module within Liferay 7 GA3.

There is a few steps that we need to take in order to compile a patched version of the module and then add it to your system.  These steps can be used for patching pretty much any module in Liferay.  But keep in mind if you run into any issues with your installation its advisable to remove all patched modules and try to recreate the issue using a clean installation of Liferay before you report the issue.

The process for patching a module is really broke down into two main areas: Compiling the custom module and adding the custom module to your Liferay installation.

Compiling the custom module

In this section we will clone the repository where the module resides and compile the module.  In the case of this example, the fix has already been committed to the Github repository so no code changes are necessary.  We do need to modify the version of the module to create a snapshot version of the module we are replacing in Liferay 7.
 
Clone and Compile the module:
  1. Clone the com-liferay-portal-osgi-web repository from github: git clone https://github.com/liferay/com-liferay-portal-osgi-web.
  2. From within the bnd.bnd file in portal-osgi-web-servlet-jsp-compiler set the version to 2.0.7.IDENTIFIER where IDENTIFIER  is whatever you want it to be for example: 2.0.7.PATCH-1.
  3. Compile the module by running the following from within the portal-osgi-web-servlet-jsp-compiler directory: gradle assemble.
  4. This will create a new version of the bundle called com.liferay.portal.osgi.web.servlet.jsp.compiler-2.0.7.PATCH-1.jar in: portal-osgi-web-servlet-jsp-compiler/build/libs
  5. Rename com.liferay.portal.osgi.web.servlet.jsp.compiler-2.0.7.PATCH-1.jar to: com.liferay.portal.osgi.web.servlet.jsp.compiler.jar removing the version identifier

Deploying the custom module to Liferay

With Liferay 7 all of the out of the box modules are provided inside Liferay LPKG files which are zip files.  In order to override an out of the box module, a patched version of the module should be copied to an override directory in osgi/marketplace directory. If the module being overridden is located inside of Liferay CE Static.lpkg it will be to be copied inside of osgi/static instead.  Liferay should not be running when performing these steps.
 
Replacing the original module:
  1. Copy the patched module into osgi/static/override since the original module resides inside of the Liferay CE Static.lpkg file.
  2. Start Liferay
  3. Once Liferay is started login to the Gogo shell with telnet localhost 11311 and type: lb | grep 2.0.7.PATCH-1.  This should show that your patched module is deployed and running.
Blogs
[...] Hello Lokesh, I just wrote a blog entry that hopefully addresses what you are trying to do. I even used the ticket you mentioned as an example:... [...] Read More
[...] Hey Marco, The issue you are running into with Liferay 7 GA2 is this one: https://issues.liferay.com/browse/LPS-66814 I just created a blog entry with instructions for patching the affected module... [...] Read More
[...] Overriding LPKG Files: A while back I wrote a blog entry on patching OSGi modules. The orginal process wasn't very elegant because it involved altering the out of the box .lpkg files. GA3 now... [...] Read More
[...] Overriding LPKG Files: A while back I wrote a blog entry on patching OSGi modules. The original process wasn't very elegant because it involved altering the out of the box .lpkg files. GA3 now... [...] Read More
Do you know why getRequestDispatcher(/abc.jsp) is not working with OSGi ? It gives null pointer exception each time with OSGi module.
Hi Jamie,

I actually override jsps using Fragment-Host which seems updating jsps but having one strange issue which is , that fragment host module is not able to load custom classes which i load from other module. I already exported and imported those modules. Any input here ?
Hi Jamie,

"This procedure is only meant for use by Liferay 7 CE. Customers using Liferay DXP should continue to using the patching instructions provided in the offical documentation."

For this comment could you please provide the link for Liferay DXP
hii Jaime , Thanks you so much for information,
Where I can find theme related patches ?