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
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 { }
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
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.
After building the project we will get the bundle under libs folder
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.