Override Liferay OSGI Module

blog-banner

In some cases we need some changes in the Liferay’s existing module for which we can extend the Liferay module and do changes as per our requirement.

To override Liferay OSGI module, you need a module that provides a complete copy of the original module. In which you can make any modifications as per your requirements.

In this article, we have described step by step guide to override a Liferay OSGI module. We hope you have some basic knowledge about Liferay IDE and Liferay Portal.

How to Override Liferay OSGI module

In this Example, we are overriding com.liferay.login.web module which is the Liferay login module. We have changed Login MVC Render command as well as login.jsp

1. Create a module project LoginWebExt.

2. Copy source code of bnd.bnd file from com.liferay.login.web module Liferay portal and paste in our bnd.bnd file.

3. Using Gogo Shell you can find Bundle-Name, Bundle-SymbolicName, and Bundle-Version.

4. The only addition to bnd file is that Include-Resource BND declaration Include-Resource: @com.liferay.login.web-2.0.4.jar

How to Override Liferay OSGI module

5. Copy below code and paste into your build.gradle file.

dependencies {
    
    compileOnly group :  "com.liferay", name: "com.liferay.captcha.api", version: "1.1.0"
    compileOnly group :  "com.liferay", name: "com.liferay.captcha.taglib", version: "1.0.0"
    compileOnly group :  "com.liferay", name: "com.liferay.frontend.taglib", version: "2.0.0"
    compileOnly group :  "com.liferay", name: "com.liferay.osgi.service.tracker.collections", version: "2.0.0"
    compileOnly group :  "com.liferay", name: "com.liferay.petra.content", version: "1.0.0"
    compileOnly group :  "com.liferay", name: "com.liferay.petra.lang", version: "1.0.0"
    compileOnly group :  "com.liferay", name: "com.liferay.petra.string", version: "1.0.0"
    compileOnly group :  "com.liferay", name: "com.liferay.portal.upgrade", version: "2.0.0"
    compileOnly group :  "com.liferay.portal", name: "com.liferay.portal.impl", version: "2.0.0"
    compileOnly group :  "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.38.0"
    compileOnly group :  "com.liferay.portal", name: "com.liferay.util.java", version: "2.0.0"
    compileOnly group :  "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.7.0"
    compileOnly group :  "javax.portlet", name: "portlet-api", version: "2.0"
    compileOnly group :  "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
    compileOnly group :  "javax.servlet.jsp", name: "javax.servlet.jsp-api", version: "2.3.1"
    compileOnly group :  "org.osgi", name: "org.osgi.core", version: "5.0.0"
    compileOnly group :  "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"  
   


   compileOnly group: 'org.slf4j', name: 'slf4j-api', version: '1.7.2'   
   compile group: "com.liferay", name: "com.liferay.login.web", version: "2.0.4"


}


jar.archiveName = 'com.liferay.login.web.jar'

6. Here the dependencies mostly comes from the build.gradle file of the com.liferay.login.web module.

7. We need to add as a compile option and specifying the archive name of the module that we're building a replacement for, In our case the com.liferay.login.web module and also add “org.slf4j” as a compileOnly option.

8. Override File : Add “login.jsp” in ”/liferay-login-web-ext/src/main/resources/META-INF/resources/” folder.

9. Copy source code of login.jsp from the Liferay portal in your custom “login.jsp”. You can add your changes into this file. Ex. Create a custom button.

10. For modifications in any file, we need to make sure it should be in the same folder hierarchy, same packages, same file name.

11. Change Render Command : Add “LoginMVCRenderCommand.java” in ”/liferay-login-web-ext/src/main/java/com/liferay/login/web/internal/portlet/action” folder. Copy the source code of LoginMVCRenderCommand.java from the Liferay portal in your custom “LoginMVCRenderCommand.java” and add a logging statement at the beginning of the render method.

Change Render Command

12. Now, build and deploy “com.liferay.login.web.jar” on the server.

Restrictions for Deploying The Module :

  1. Make sure the portal is not running when we do the deployment.
  2. The build jar file must be copied manually to the $LIFERAY_HOME/osgi/marketplace/override folder.
  3. The $LIFERAY_HOME/osgi/state folder must be deleted.
  4. If you have changed any web-type file (javascript, JSP, CSS, etc.), you should delete the relevant folder from the $LIFERAY_HOME/work folder.
  5. Our changes may not be reflects if Liferay deploys a newer version than the one declared in our bundle.

Now start server verify the changes, by navigating to the $LIFERAY_HOME -> Sign In :

Customize Login.jsp page

Now check out Liferay log output :

Liferay Log Output

Contact us

For Your Business Requirements

Text to Identify Refresh CAPTCHA
Background Image Close Button

2 - 4 October 2024

Hall: 10, Booth: #B8 Brussels, Belgium