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

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 leaps language barrier with translator phone

GOOGLE is developing software for the first phone capable of translating foreign languages almost instantly — like the Babel Fish in The Hitchhiker’s Guide to the Galaxy. By building on existing technologies in voice recognition and automatic translation, Google hopes to have a basic system ready within a couple of years. If it works, it could eventually transform communication among speakers of the world’s 6,000-plus languages. The company has already created an automatic system for translating text on computers, which is being honed by scanning millions of multi-lingual websites and documents. So far it covers 52 languages, adding Haitian Creole last week. Google also has a voice recognition system that enables phone users to conduct web searches by speaking commands into their phones rather than typing them in. Now it is working on combining the two technologies to produce software capable of understanding a caller’s voice and translating it into a synthetic equivalent in a foreign ...

Keyboard First Impressions: Kinesis Advantage Mechanical Ergonomic Keyboard

An ergonomic keyboard with mechanical switches that’s looking to attract users interesting in a high quality, highly ergonomic offering and don’t mind the rather steep learning curve or the price. The  TECK  isn’t the only such keyboard, of course, and I decided to see what other mechanical switch ergonomic keyboards I could get for comparison. Next up on the list is the granddaddy of high-end ergonomic keyboards, the  Kinesis Contour Advantage . I wanted to provide my first impressions of the Kinesis, along with some thoughts on the initial switch and the learning curve. This time, I also made the effort to put together a video of my first few minutes of typing. It actually wasn’t as bad as with the TECK, but that’s likely due to the fact that I already lost many of my typing conventions when I made that switch earlier this year. I’ll start with the video, where I take a typing test on four different keyboards and provide some thoughts on the experience, and then ...