A few days ago I had the happy idea of updating the version of OpenJDK from 11.0.5 to 11.0.6. It seemed that everything went in the right direction but I was struck by the famous proverb
Don't leave the old road for the new one
When starting Liferay Portal 7.2 GA2 CE here you will see the pretty hateful error indicated below (in console 1).
After some research I discovered that the error is due to a bug (again open) on OpenJDK 11.0.6 [JDK-8237875 (zipfs) Directory Stream entries changed behavior between JDK 11.0.5 and JDK 11.0.6](https://bugs.openjdk.java.net/browse/JDK- 8237875)
Liferay for its part has taken steps to resolve, even quickly, through LPS-107983 - OpenJDK 11.0.6 compatibility problem. This LPS is already closed and solves the problem on the 7.x and master branches.
How can we patch the LPS without waiting for the new GA to come out?
The possible solutions are:
- Downgrade OpenJDK to version 11.0.5;
- If we have the DXP we are in a position to request support directly from Liferay;
- If we have the CE we can apply the patch autonomously.
The first way is not always viable due to the fact that most of the Sometimes the JDK update is one of those components whose update is centralized and we have therefore little room for maneuver.
The second route is easy to follow and usually in a few days gets the Hot Fix.
In order not to miss anything, I would say to choose the third way, which is the most interesting one.
1. How to apply the patch
Let's see how it is possible and simple to apply the patch to Liferay Portal CE. The reference version is Liferay CE Portal 7.2.1 GA2.
How can we apply our Hot Fix also on the CE? The answer it's really simple: Overriding lpkg files.
The bundle we need to patch to (https://patch-diff.githubusercontent.com/raw/brianchandotcom/liferay-portal/pull/84189.patch) 84189 is Liferay Portal OSGi Web Servlet JSP Compiler (com.liferay.portal.osgi.web.servlet.jsp.compiler) which is part of the LPKG Liferay CE Static - Impl.lpkg. In this case we can then apply the Overriding lpkg files, even to the Static ones.
The procedure to follow is:
- Create the jar format bundle containing the patch;
- The bundle name must be the same as the original, minus the version information;
- Copy the bundle .jar file to the
- Remove the contents of the
- Launch Liferay Portal. Note that every time they add and remove .jars like this, you need to close and restart Liferay Portal for make the changes effective.
If you need to restore your customizations, delete the .jar files replacement: Liferay Portal will use the original .jar file to the next start.
It all seems very clear!
How do we create the new bundle that will contain the LPS-107983 patch? We will see this in the next chapter.
2. How to create the bundle with the patch
To create the new bundle you need the sources and to get them they exist essentially two ways which are:
- Clone of the sources of Liferay Portal 7.2.1 GA1 from the GitHub repository;
- Obtain the sources from the Maven repository com.liferay.portal.osgi.web.servlet.jsp.compiler version 4.0.14.
The choice of the first road could take a long time because of the
clone of the repository which even if executed with the
--depth 1 option takes some time.
Personally I chose the second path, which in a few minutes will allow us to get the bundle with the patch. To follow all the necessary steps (and not necessary no IDE). Here is the list of macro tasks:
- Creation of a Liferay Workspace via blade;
- Creating the directory structure for the
- Copy the sources from the bundle jar downloaded from the Maven repository into the module on Liferay Workspace;
- Download the bnd.bnd from the Liferay GitHub repository and place it on the root of the module;
- Download the build.gradle from Liferay's GitHub repository and place it on the module root;
- Modify the build.gradle to add FileUtil (com.liferay.gradle.util.FileUtil);
- Apply the patch 84189;
- Build the module;
- Make sure the portal is turned off;
- Install the module in
- Start the portal.
The set of commands shown below carry out steps 1 to 5. If you want save this time too, then you can draw directly on repository that I have prepared for you https://github.com/smclab/apply-lps-107983-openjdk-11-0-6
Step 6 requires editing the build.gradle file, this is necessary so that you do not get the error shown below.
To avoid the error, the content must be added to the build.gradle file shown below.
At this point we are in a position to apply the patch in the following way.
If everything goes as it should, you should see an output similar to the one shown in the following figure.
Once applied we can proceed with the build of the bundle using the classic build command
With the portal off, we copy the new bundle (without the version) inside
At this point, after deleting the contents of the directory
$LIFERAY_HOME/osgi/state/, we start the portal. Watch out for Liferay's logs
why you should see the following log lines indicating the happened
installation of the new bundle that overrides the existing one.
Once the portal is up and running, deploy any MVC portlet e check that you no longer get compilation errors on the JSPs. Figures a following show the home page of the Liferay portal before and after installation bundle with the patch.
In these cases, when we go to patch Liferay components, it is advisable to highlight it, for example with a suitable indication on the Bundle Name.
Very well! Now we have our Liferay 7.2 GA2 Portal that works with OpenJDK 11.0.6
In this article we have seen how simple it is to apply a patch to a core component of Liferay without the need to wait for the next release. All this is made possible for three simple reasons:
- Liferay is Open Source;
- Liferay since version 7.0 has adopted in full OSGi, ergo, the welcome to modularity;
- Liferay has developed sets of frameworks that facilitate its extension, including the core components of the portal.
Before you throw in the towel when you encounter a problem that may seem insurmountable, I always advise you to consult the documentation of Liferay where in most of you could find the solution to your problem.