I felt compelled to write a very simple portlet so that I and others can build new portlets from a simple code base.

The Portlet Class

Create the file Simplest.java in a directory called simplest/WEB-INF/classes

public class Simplest extends javax.portlet.GenericPortlet {
    public void doView(javax.portlet.RenderRequest request, javax.portlet.RenderResponse response)
                throws javax.portlet.PortletException, java.io.IOException
            response.getWriter().println("A very simple portlet.");

Compile the class using the command,

javac -cp ~/.maven/repository/jetspeed2/jars/portlet-api-1.0.jar Simplest.java

The portlet.xml

Create the file portlet.xml in the simplest/WEB-INF directory.

<?xml version="1.0" encoding="UTF-8"?>
<portlet-app id="simplest" version="1.0">
  <portlet id="Simplest">
    <display-name>Simple Display Name</display-name>
      <title>Simple Title</title>
      <short-title>The world's simplest portlet</short-title>

The web.xml

Create the file web.xml in the simplest WEB-INF directory.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  <description>The world's simplest portlet</description>


Create the file simplest.psml in the src/webapp/WEB-INF/pages directory of your Jetspeed Portal. The portlet-app id and the portlet-name are combined to identify the portlet fragment. Rebuild your portal.

  <title>The simplest portlet in the world</title>
  <metadata name="title" xml:lang="fr">La plus simple portlet du monde</metadata>

  <fragment id="simplest" type="layout" name="jetspeed-layouts::VelocityTwoColumns">
    <fragment id="simplest-1" type="portlet" name="simplest::Simplest">
      <property layout="TwoColumns" name="row" value="0" />
      <property layout="TwoColumns" name="column" value="0" />


The WAR file

From the directory simplest combine the files above into a war file using the command,

jar cvf ../simplest.war .

Deploy the WAR file

Copy the war file to $CATALINA_HOME/webapps/jetspeed/WEB-INF/deploy

Jetspeed will deploy the webapp. Access the page in your navigator http://localhost:8080/jetspeed/portal/simplest.psml

Jetspeed2/QuickstartForTheImpatient/VerySimplePortlet (last edited 2009-09-20 23:46:32 by localhost)