Skip to main content

Liferay 7 - MVC Portlet via Maven

Leveraging OSGI Module

Liferay leverages the OSGi framework to provide a development environment for modular applications. There are many OSGi best practices that Liferay Portal follows to provide an easy-to-develop-for platform. Here, we are not going to talk about these rather we will focus on developing our first Liferay 7 Portlet.

1. Create a folder : D:\Workspace\Liferay7

2. Open your command prompt as Administrator

C:\windows\system32>cd D:\Workspace\Liferay7
C:\windows\system32>d:
D:\Workspace\Liferay7>

3. Execute the below command

D:\Workspace\Liferay7>mvn archetype:generate -DarchetypeGroupId=com.liferay -DarchetypeArtifactId=com.liferay.project.templates.mvc.portlet -DgroupId=com.mindtree -DartifactId=com.mindtree.sample.portlet -DinteractiveMode=false -DclassName=Sample -Dauthor=AtifAliSiddiqui

Note:
- Before executing the above command, make sure you have installed Maven on your machine.
- Wait for the "BUILD SUCCESS" message to appear
Important:
In maven everything is a plugin. So Archetype is also a plugin.

Each plugin is identified by Group Id, Artifact Id and version.
In our case we have used an Archetype Plugin.
- GroupId is com.liferay
- ArtifactId is com.liferay.project.templates.mvc.portlet.
4. Please verify the generated directory structure looks as classified below

- com.mindtree.sample.portlet
----- src
--------- main
------------- java
----------------- com
--------------------- mindtree
------------------------- portlet
----------------------------- SamplePortlet.java
------------- resources
----------------- content
--------------------- Language.properties
----------------- META-INF
--------------------- resources
------------------------- init.jsp
------------------------- view.jsp
----- .gitignore
----- bnd.bnd
----- build.gradle
----- pom.xml

5. Import this maven project into eclipse.

- Open up eclipse.
- Mention the Workspace as "D:\Workspace\Liferay7".
- On the Left hand side, Package Explorer. Right click and select Import.
- Expand "Maven", choose "Existing Maven Projects".
- Root Directory - "D:\Workspace\Liferay7".
- The maven project we just created should appear and be selected under projects. Click Finish.

6. Add some text to your view.jsp

- In Package Explorer, go to "src/main/resources/META-INF/resources/view.jsp"
- Enter the following
<%@ include file="/init.jsp" %>


This is the first Portlet created by Atif.
7. Lets build our Project / Portlet

- In Eclipse select "Run" -> "Run Configurations"
- Right click "Maven Build" -> New
- Name :: Build Portlet
- Base directory :: ${workspace_loc:/com.mindtree.sample.portlet}
- Goal :: clean package
- Click Apply
- Click Run
- Check in Console if the Build is Successful

8. Lets Deploy our Portlet to Liferay

- Start up your Liferay7 instance, if not already running.
- Copy the "com.mindtree.sample.portlet-1.0-SNAPSHOT.jar" from "D:\Workspace\Liferay7\com.mindtree.sample.portlet\target".
- Paste "com.mindtree.sample.portlet-1.0-SNAPSHOT.jar" to "D:\Liferay\Community Edition 7.0\liferay-ce-portal-7.0-ga3\deploy".
- See Liferay console / logs on the deployment of your portlet.
9. Now login to Liferay and see if your portlet has deployed, and add to page.

Comments

Popular posts from this blog

OnePlus 3T in 2017

Hi there, I just bought OnePlus 3T, why? Even when OnePlus 5 is out and OnePlus 5T looming around the corner. Top five reasons why the 3T might just be a very sound investment if you are in the market for a new phone. 3T is going for a relatively cheap price. Its wickedly fast. Its 1080p display. Its software. OnePlus 5 isnt a huge update. Key Specs Display - 5.50-inch Processor - 1.6GHz quad-core Front Camera - 16-megapixel Resolution - 1080x1920 pixels RAM - 6GB OS - Android 7.1.1 Storage - 64GB Rear Camera - 16-megapixel Battery Capacity - 3400mAh Overall Rating 9/10 - Design 9/10 - Display 9/10 - Software 9/10 - Performance 9/10 - Battery life 9/10 - Camera 9/10 - Value for money Important - No other phone with all round 9's. Good Solid system and app performance Very good battery life Competent set of cameras Amazing premium build quality Good value for money Bad Nothing as yet

Everything about Java 8

The following post is a comprehensive summary of the developer-facing changes coming in Java 8. This next iteration of the JDK is currently scheduled for general availability in  September 2013 . Read More

Google tablet to give Apple a touch of its own medicine

Google is trying to one-up Apple, showing off designs for a new tablet computer based on its Chrome operating system that would be a direct rival to the iPad. Just weeks after launching its own iPhone competitor in the US, the Nexus One, Google might soon extend its competition with Apple further as it seeks to push its search and other products on to as many devices as possible. Google's user interface designer, Glen Murphy, published mock-ups of a Google tablet on the search giant's Chromium.org website, along with a video of how users would interact with the device. Late last year Google announced Chrome OS, an operating system predominantly for small netbooks that would be based around the web browser, providing quick boot times and easy access to Google's array of online services. The first Chrome OS netbooks are due to arrive this year, but Google is now considering extending the platform to other devices including tablets, desktops and even big screen TVs. Chrome OS ...