Portal properties are configuration points from where we can change behavior / functionality of 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.
admin.email.from.name=Test Test default.admin.first.name=Test default.admin.last.name=Test liferay.home=C:/Liferay Developer Studio 1.5/resources/liferay-portal-6.1.10-ee-ga1 [email protected] company.default.name=Liferay [email protected] company.default.locale=en_US setup.wizard.enabled=false default.admin.screen.name=test
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
On server 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 property defined in portal.properties file, can be overridden in portal-ext.properties defined at location-1.
- Any property 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.
Click on the Open button and search for company.default.name property. It has the 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.
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
Add following content to portlet class
@Override
public void render(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
String newProp = PropsUtil.get("test.property");
String existingProp = PropsUtil.get("company.default.web.id");
request.setAttribute("newProp", newProp);
request.setAttribute("existingProp", existingProp);
super.render(request, response);
}Explanation:-
- We have an override render method that will be called when this portlet gets 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 the property is not defined.
- We are setting properties value in request attribute which will access it in view.jsp
open view.jsp and add the following code in it.
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
Existing Property is <b>${existingProp}</b>
New Property is <b>${newProp}</b>Explanation:-
- In view.jsp file, we are showing the value of properties by EL.










