Portal Properties and Portal-ext Properties in Liferay

Portal properties are configuration points from where we can change behavior / functionality of liferay portal.
Liferay provides many portal properties which can be used to set up & configure Liferay portal.
When we configure liferay server first time, it will create portal-setup-wizard.properties file under <<Liferay-tomcat-bundle>> folder as per below screenshot.
Portal Properties and Portal-ext Properties in Liferay - Configuration_zip
This file contains following configuration information.


Liferay defines few more portal properties in portal.properties file. This file is located in <>/tomcat-7.0.25/webapps/ROOT/WEB-INF/lib/portal-impl.jar. We can override these properties (defined in portal.properties) from portal-ext.properties file.


portal-ext.properties file needs to be created manually and can be placed at following places

Location-1 : <<Liferay-Tomcat-Bundle>>/ folder
Location-2 : <>/tomcat-7.0.25/webapps/ROOT/WEB-INF/classes.


On sever startup, Liferay reads portal properties from portal.properties file followed by portal-ext.properties file defined at location-1 then from location-2. Finally it reads from portal-setup-wizard.properties file.

This means, 

  • Any properties defined in portal.properties file, can be overridden in portal-ext.properties defined at location-1.
  • Any properties defined in portal-ext.properties file at location-1, can be overridden in portal-ext.properties defined at location-2.

We can either override existing properties and / or can define new properties  in portal-ext.properties file.

Portal properties

Let’s see this in action.

Follow blog to configure Liferay source in eclipse / Liferay Developer Studio.

Once Liferay source is imported, press Ctrl+Shift+R and type portal.properties file as per below screenshot.

Portal Properties and Portal-ext Properties in Liferay - Open_Portal.properties

click on Open button and search for company.default.name property. It has following value

company.default.name=Liferay


we will override this property from portal-ext.properties file.  Create portal-ext.properties at <<Liferay-Tomcat-Bundle>> folder as per below screenshot. 

Portal Properties and Portal-ext Properties in Liferay - location-1

Add following content to it.

company.default.web.id=abc.com
test.property=Abc Corporation

Here we are overriding existing property company.default.web.id and added new (custom)property test.property with value Abc Corporation.


Create one more fie with same name (portal-ext.properties) at <>/tomcat-7.0.27/webapps/ROOT/WEB-INF/classes path and add following content to it.


company.default.web.id=pqr.com

test.property=Pqr Ltd

portal-ext.properties file placed at <>/tomcat-7.0.27/webapps/ROOT/WEB-INF/classes will be read last and hence it overrides all properties defined in portal.properties and portal-ext.propeties (defined at <<Liferay-Tomcat-Bundle>> folder).


We will read these properties from Portlet. Follow my previous blog to create Liferay MVC portlet. Give its name as ‘portal-properties-check‘ and ‘-portlet‘ will be appended by Liferay at the end.


I gave Portlet class as ‘com.opensource.techblog.portlet.PortletPropTestPortlet‘. It will look like as per below screenshot

Portal Properties and Portal-ext Properties in Liferay - Project_structure

Add following content to portlet class


Explanation:-

  • We have override render method which will be called when this portlet get rendered on liferay page.
  • In this method, we are reading properties defined in portal.porperties (or portal-ext.properties) by util class called PropsUtil.get() method. We are passing Key of property. This method will return value (in form of ‘String‘ if present) or null if property is not defined.
  • We are setting properties value in request attribute which will access it in view.jsp

open view.jsp and add following code in it.


Explanation:-

  • In view.jsp file, we are showing the value of properties by EL.
Note:- We must have to restart the server to reflect any changes done in portal-ext.properties file.
 
Since we have placed portal-ext.properties file first time, restart the server (if it’s already running). Once server is restarted, then deploy the portlet and place it on some liferay page. You will see following out put.
Portal Properties and Portal-ext Properties in Liferay - output-1
As you can see the values of above properties are coming from portal-ext.properties defined at <>/tomcat-7.0.27/webapps/ROOT/WEB-INF/classes location. It overrides properties defined in portal.properties and portal-ext.properties (defined at <<Liferay-Tomcat-Bundle>> folder) file.
 
Now, remove ‘test.property=Pqr Ltd‘ property from portal-ext.properties file located at <>/tomcat-7.0.27/webapps/ROOT/WEB-INF/classes path and restart the server. This time you will see following out put.
Portal Properties and Portal-ext Properties in Liferay - output-2
Note that, value of ‘company.default.web.id‘ property is still coming from portal-ext.properties file defined at <>/tomcat-7.0.27/webapps/ROOT/WEB-INF/classes but the value of ‘test.property‘ is coming from portal-ext.properties at <<Liferay-Tomcat-Bundle>> location, since we have deleted it from portal-ext.properties file located at <>/tomcat-7.0.27/webapps/ROOT/WEB-INF/classes.
 
This means, portal-ext.properties file located at <>/tomcat-7.0.27/webapps/ROOT/WEB-INF/classes always read last and override all properties from portal.properties and portal-ext.properties defined at <<Liferay-Tomcat-Bundle>> folder.
 
Play with some other properties by overriding and displaying it from portlet.
 
You can find more properties defined in portal.properties from Liferay site.
 
I would recommend looking at index page ‘A Complete Liferay Guide‘ to browse all topics about liferay.

 

Download Source
Download Source

Share This Post

Post Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.