• Liferay 7 Portlet Creation using Liferay IDE

    Posted on August 31, 2016 by Hamidul Islam in liferay 7.

    Quick-Start-Portlet-Development

    aimPrior to  Liferay 7  we used either Plugin SDK or maven for portlet creation. Liferay 7 has introduced the concept of OSGI where we can avoid Plugin SDK.In OSGI everything is treated as module. In this article I will explain how to create a sample portlet using Liferay IDE. The sample portlet would be nothing but OSGI module.


    Before you follow this article ensure ensure that below 2 items are installed properly in your machine.

    1. liferay-portal-tomcat-7.0-ce-ga1-20160331161017956.zip

    2. Liferay IDE 3.0.1.201606151031-ga2


    Create the Project in Eclipse:

    So to start with lets create new Liferay Module Project in eclipse. Navigate in the eclipse

    New→Other→Liferay→Liferay Module Project

    Liferay Module Project

    Generated Portlet Class:

    As based on input given to the IDE the generated portlet class is

    package com.proliferay.portlet;
    
    import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
    
    import javax.portlet.Portlet;
    
    import org.osgi.service.component.annotations.Component;
    
    @Component(
    	immediate = true,
    	property = {
    		"com.liferay.portlet.display-category=category.sample",
    		"com.liferay.portlet.instanceable=true",
    		"javax.portlet.display-name=sample-portlet Portlet",
    		"javax.portlet.init-param.template-path=/",
    		"javax.portlet.init-param.view-template=/view.jsp",
    		"javax.portlet.resource-bundle=content.Language",
    		"javax.portlet.security-role-ref=power-user,user"
    	},
    	service = Portlet.class
    )
    public class SamplePortlet extends MVCPortlet {
    
    }
    

     

    liferay-portlet-class-property-section

     

    Note 1:

    Prior to Liferay 7 we used  portlet.xml as portlet descriptor. In Liferay 7 we can create portlet even without using portlet.xml. However the equivalent xPath of portlet.xml can be used as OSGI portlet service property as shown in the above code. For all the mappings you can look here

    https://dev.liferay.com/develop/reference/-/knowledge_base/7-0/portlet-descriptor-to-osgi-service-property-map 

    Note 2:

    In general we deploy liferay portlet as WAR file. However in OSGI based application everything is considered as bundle which is nothing but JAR file. To build the OSGI bundle or JAR, use Gradle Tasks view in the eclipse.

    Gradle-Tasks-View

    After building the project we will get the bundle under libs folder

    portlet-as-osgi-bundle

    Note 3:

    We can deploy the bundle in the hot deploy folder of Liferay. Once the portlet is deployed we can add the portlet in Liferay page as usual. 

    Summery:

    The sample example is to quick start portlet development in Liferay 7. In the portlet class no code has been written.All the files are generated by Liferay IDE. You can download the portlet and deploy in your machine to explore it further. 

     

    Download Sample Portlet

One Response so far.

  1. Aravind L says:

    This article really helpful for my project using liferay 7 . I got the clear Idea of liferay 7.

Top
%d bloggers like this: