Skip to main content

Creating OSGi Modules and Sharing Packages

  Overview This guide walks through creating two OSGi modules in Liferay 7.4 and sharing a Java package between them using the standard API + Implementation pattern. This is the most common and correct approach for exposing reusable services in a Liferay-based architecture. In OSGi, a bundle (module) does not expose its internal packages by default — everything is private unless explicitly exported. To share code between modules, the standard practice is to split functionality into: · An API module — contains interfaces/DTOs and exports the package · A Service (Implementation) module — implements the interface, imports the package, and registers the implementation as an OSGi component/service The consuming module then simply imports the API package and looks up the service using @Reference injection. Step 1: Create the API Module Using Liferay Workspace + Blade CLI, generate a new API module: blade create -t api -p com.sgc.greeting greeting-api This generates a Gradle module unde...

Liferay DXP 7.4 – Custom Development Environment Setup

 

Liferay DXP 7.4 – Custom Development Environment Setup


1. Prerequisites

Required Software

  • JDK 11 or 17 (DXP 7.4 supported versions)

  • Gradle (comes with workspace)

  • Node.js (for frontend modules)

  • Git

  • MySQL / PostgreSQL

  • Application Server (usually Apache Tomcat 9)

  • Blade



2. Create Liferay Workspace

Set Java 17


blade init -v 7.4 dxp-workspace-demo
cd my-dxp-workspace-demo




Blade Installing from the Graphical Installer

If you’re more comfortable with an installer, download the latest Liferay Project SDK Installer and run it.

  1. Select your Java runtime. This should be auto-detected.



  1. After the introduction, click Next.

  2. You can initialize a Liferay Workspace during the install. Liferay Workspace is an environment (a set of folders) on your system for Liferay projects. Set its location if you wish to initialize it now.

  1. If you’re initializing a Liferay Workspace, you must next choose Liferay DXP or Community Edition.



Choose the product type and click Next.

  1. Click Next to install Blade CLI.

Configure DXP 7.4 Product

Open:

gradle.properties

Check or update this line:

liferay.workspace.product=dxp-7.4-uXX

Replace uXX with your update version, for example:

liferay.workspace.product=dxp-7.4-u92

If you're using Community instead:

liferay.workspace.product=portal-7.4-ga92

Next Step – Initialize Bundle

From inside:

dxp-workspace-demo

Run:

gradlew initBundle










This will:

  • Download DXP/CE

  • Setup Tomcat

  • Create bundles folder

After completion, you’ll see:

bundles/





Folder & File Explanation (Liferay 7.4 Bundle)

data/

🔹 Stores runtime data generated by Liferay.

Contains:

  • Document Library files

  • Search indexes

  • HSQL database (if default DB)

  • OSGi state cache

deploy/

🔹 Hot deploy folder.

If you drop:

  • JAR (OSGi module)

  • WAR

  • LPKG

Liferay auto-deploys it.

Used mostly for quick manual deployments.

elasticsearch-sidecar/

🔹 Embedded Elasticsearch instance.

Used when:

  • You are not using external Elasticsearch

  • Default dev setup

In production, you should use external Elasticsearch cluster.

glowroot/

🔹 Performance monitoring tool (APM).

  • Used for profiling

  • JVM performance tracking

  • Thread & memory monitoring

Enterprise teams use this for debugging performance issues.

license/

🔹 Stores DXP license files (not used in Community Edition).

logs/

🔹 All server logs go here.

Important files:

liferay.log
catalina.out

First place to check if server fails.

osgi/

🔹 Core of Liferay 7.4 architecture.

Contains:

  • modules/

  • configs/

  • marketplace/

  • state/

This is where OSGi runtime lives.

Your custom modules get deployed here.

routes/

🔹 Used for React / SPA routing.

Modern Liferay front-end routing support.

tomcat/

🔹 Application server (Apache Tomcat).

Contains:

bin/
conf/
lib/
logs/
webapps/

Start server from:

tomcat/bin/startup.bat

tools/

🔹 Internal utilities & scripts used by Liferay.

work/

🔹 Temporary compiled JSP files and Tomcat cache.

Can be deleted if server has issues.

Important Files

.liferay-home

Marks this directory as Liferay Home

.liferay-version

Stores current portal version.

.githash

Internal build reference.­

portal-ext.properties

🔹 Most important customization file.

Used to override:

  • Database config

  • Mail config

  • CAS config

  • LDAP

  • Clustering

  • Cache settings

Example DB config:

Configure Database



Edit:

bundles/osgi/configs/com.liferay.portal.store.db.configuration.DBStoreConfiguration.config

Or set in portal-ext.properties:

jdbc.default.driverClassName=com.mysql.cj.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost:3306/lportal
jdbc.default.username=root
jdbc.default.password=yourpassword

Start DXP Server

cd bundles/tomcat/bin
startup.bat





Access:

http://localhost:8080






Create Custom Module

Create MVC Portlet

blade create -t mvc-portlet -p com.sgc.demo demo-portlet




Project structure:

demo-portlet/
├── bnd.bnd
├── build.gradle
├── src/main/java
├── src/main/resources
└── src/main/webapp

Deploy:

gradlew deploy

gradlew :modules:demo-portlet:deploy


Comments

Popular posts from this blog

service builder with crud operation in liferay

   Crud and Search opration in Liferay:      ->  Liferay use service builder techniq for Crud opration.    ->  Service builder purform by  Service.xml file.    ->  Service.xml file create table in database and also create class and diffrent method.   1)      Create service.xml file.             ->Create service.xml file in WEB-INF and write below code.             ->CODE:        < service-builder package-path = "com.test" >         < namespace > qr </ namespace >           < entity name = "Searchclass" local-service = "true"                     ...

How to create new site programmaticly in liferay with validation

Create site in liferay <%@page import="javax.portlet.PortletPreferences"%> <%@page import="com.liferay.portal.kernel.util.ParamUtil"%> <%@page import="com.liferay.portal.kernel.util.HtmlUtil"%> <%@page import="com.liferay.portal.kernel.util.StringPool"%> <%@page import="com.liferay.portal.kernel.util.UnicodeProperties"%> <%@page import="com.liferay.portal.service.LayoutSetPrototypeServiceUtil"%> <%@page import="com.liferay.portal.model.LayoutSetPrototype"%> <%@page import="com.liferay.portal.service.GroupLocalServiceUtil"%> <%@page import="java.util.List"%> <%@page import="com.liferay.portal.kernel.bean.BeanParamUtil"%> <%@page import="com.liferay.portal.theme.ThemeDisplay"%> <%@page import="com.liferay.portal.model.Group"%> <%@page import="com.liferay.portal.kernel.util.WebK...

The Ultimate Guide to Liferay DXP Performance Tuning: Speed Up Your Portal

The Ultimate Guide to Liferay DXP Performance Tuning: Speed Up Your Portal In the enterprise web space, milliseconds equal millions. Whether you are running a B2B commerce storefront, a customer support portal, or an employee intranet on Liferay DXP, slow load times will devastate your user experience and destroy your SEO rankings. Out of the box, Liferay is configured to run on almost any machine. This means its default settings are highly conservative to ensure compatibility, not maximum performance. If you are launching a production environment without tuning your server, you are leaving massive amounts of speed and scalability on the table. In this comprehensive, deep-dive guide, we are going to explore the critical layers of Liferay performance tuning. We will cover backend Java Virtual Machine (JVM) configuration, Database Connection Pooling, Elasticsearch optimization, and Frontend caching strategies. By the end of this guide, you will have a blazing-fast, enterprise-grade...