Saturday, 12 September 2009

How to Create a Simple JSR 168 Portlet using Eclipse

After understanding the basic concepts of a Portlet, like its lifecycle and its methods, it shouldn't be a problem to create a JSR compliant Portlet.

Recently I had published an article on creating a JSR 286 compliant Portlet. Here is the URL for that Blog Post.

If you are not familiar with Portlets then I will request you to read my first article in which I have discussed about the Portlet World


Here in this article we will create a new JSR 168 Portlet from Scratch using Eclipse. Later you can export this Portlet as a WAR and run it in any Portal Server like Liferay, JBoss, Jetspeed and so on.

The Steps are outlined:

Here I have used Liferay Portal which is opensource. You can download the bundle : Liferay-Tomcat at www.liferay.com

1. Download Eclipse IDE from : http://www.eclipse.org/downloads/ : I usually download the Classic version.

2. You can unzip the same in some folder. Say C:/portlet/
Create a workspace folder also say: C:/portlet/workspace

3. Unzip the Liferay Tomcat bundle also in the same folder, C:/portlet, just to keep things simple.

4. For creating Portlet using Eclipse IDE you need to install Eclipse Portlet plugin available at http://sourceforge.net/projects/portlet-eclipse/
You can look for updates in Eclipse by going to help-->install new software . Here you can provide the url and download the plugin.
I will also suggest you to download the J2EE package which helps you in creating JSP and Servlets also. Just look for updates in eclipse and you will find options related to Java/J2EE.

5. Once this is done, restart Eclipse. Create a dynamic Web Project by going to :
File-->New-->Other-->DynamicWebProject If you cannot see this option you need to update to use web development.

6. Your project can be given any name: for instance Hello World.

7. Once this is done right click on your project name and create a new Portlet. If you are unable to see this option then your plugin is not properly installed.

8. The wizard will guide you through the steps and create a Portlet for you say a Hello World Portlet.

9. Expand the project to see the file structure. You will find portlet.xml file in the WebContent folder. This is the main file where all your Portlets are defined. I will discuss this file separately.

10. So you are almost done. Next right click on your project and Export your project as WAR in some directory.

This WAR can now be deployed to any server. For Liferay you can place it in the C:/deploy folder from where Liferay auto deploys it on startup.

PN: You need to setup two environment variables for Portal Server : JAVA_HOME and CATALINA_HOME. JAVA_HOME is basically the path to your jdk home folder. And CATALINA_HOME is the path of your tomcat server.

Next when you will start your Portal you will be able to add the Portlet from the admin page.

In my next article I will discuss how to Create a Struts Portlet using Eclipse and Portlet Plugin. Also I will discuss files in a Web Project : web.xml , struts-config.xml and portlet.xml



5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi!
    How could I login to admin page and upload a portlet? I download the liferay with Tomcat 5.5

    ReplyDelete
  3. You can create an account or you can login with default login : test@liferay.com and test as password

    ReplyDelete
  4. Hello ,
    I am able to create a simple portlet on eclipse but i want to create a portlet in which i want a jsp page through which i want to submit my form data into data base (mongodb) and retrieve it back on next jsp page ....Can you pls help me out for this.

    ReplyDelete