How to read and write properties files in liferay

Liferay developer sometimes need to read and write properties files.

1.     For golobal configurations one can put properties valuse on portal.properties
    You can acheive this by overwrite portal.properties using Liferay Hook.
    As below:

    <?xml version="1.0"?>
    <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd">

    <hook>
        <portal-properties>portal.properties</portal-properties>
    </hook>


    and then write your requird key values in this file.
    Below sample key values:
    default.landing.page.path=/web/guest/home
    company.default.home.url=/web/guest/home

   
    To read golobal portal properties file you can use liferay com.liferay.portal.kernel.util.PropsUtil api as below:
   
    String home_url=PropsUtil.get("company.default.home.url");

2.     For portlet specific properties you can create portlet.properties file in portlet classpath
    for example WEB-INF/src/portlet.properties
    and then write your requird key values in this file.
    Below sample key values:
    courses=Java,HTML,Liferay

    To read this file you can use liferay com.liferay.util.portlet.PortletProps api as below:
   
    String courses=PortletProps.get("courses");


Enjoy..

Comments

  1. Property Web Portal allow users to easily manage listing of available properties on sale or to paying rent.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to run ofbiz as ubuntu Service.

JPA vs Spring JPA vs Spring Data JPA vs Hibernate

Java Array Interview Questions for Entry-Level Developers Part 01