Index

Step-by-Step Tutorial

Introduction

This tutorial focuses on how to create an Eclipse development environment to create and debug portlets. It does not cover portal deployment (which is different for each portal) and cheats a bit by using the struts2-archetype-portlet Maven 2 archetype. We can get away with not talking about portlet development, because Struts 2 portlet support allows a carefully-written portlet to be ran as a regular servlet application, drastically simplifying our development setup. Of course, to fully test your portlet, you will need to deploy the war into a portal server, but by running it in pure Tomcat, we can get 90% of the way there. Therefore, this tutorial requires Eclipse, Maven 2, and Tomcat to be installed.

Installing Eclipse

In the tutorial, we will be using Eclipse 3.3 which can be downloaded from http://www.eclipse.org. I recommend the JEE package, which contains the popular (and required for this tutorial) Web Tools Project.

Installing Maven 2

Installing Tomcat

Apache Tomcat can be found at http://tomcat.apache.org. To install, simply unzip the distribution to a known location on your hard drive.

Creating the project

To start, we will use the Struts 2 portlet Maven archetype, struts2-archetype-portlet, which will create a new portlet project will all the necessary files for a simple "hello world"-style portlet. Open a terminal and type:

Deploying your portlet as a servlet

Since the Eclipse project was generated with the 'wtpversion' flag, it will be immediately recognized as a web application by Eclipse. If this is your first time deploying web applications in Eclipse, you will need set up your Tomcat server. To do this in Eclipse:

Navigate to "Window -> Show View -> Other..."

Open "Server" and select "Servers". This will open a "Servers" tab, probably in your bottom tab panel.

Right-click in the new "Servers" tab and select "New -> Server"

Select the version of Tomcat you installed and click "Next"

Click "Browse" and locate your Tomcat installation, and click "Next"

If "myportlet" isn't already in the "Configured projects" column, move it over and click "Finished"

Before we can run our portlet in Eclipse, I've found that you need to add the portlet jar to Tomcat. To do this:

Right-click on the 'myportlet' project in the "Project Explorer" and select "Properties"

Click on "J2EE Module Dependencies

Click on the checkbox next to "M2_REPO/portlet-api/portlet-api/1.0/portlet-api-1.0.jar"

Click "OK"

Now, you should be able to run and debug your project in Tomcat. The way I prefer to do this is to:

Right-click on the 'myportlet' project in the "Package Explorer" and select "Run As -> Run on Server"