Sun Java System Portal Server 7.1 Developer's Guide

ProcedureTo create a portlet web application

  1. Create a complete portlet.xml file that includes the declaration for all the portlets.

    Creating a Portlet Web Application contains the portlet.xml file that includes the declaration for the sample portlet. The portlet.xml file includes name, class, and cache information. Since the sample portlet also uses preferences, the preference setting is also included in the portlet.xml file. Also PrefPortlet supports the EDIT as well as HELP mode; so the supported modes are specified in the portlet.xml file.

    portlet.xml File for the PrefPortlet


    <?xml version="1.0" encoding="UTF-8"?>
    <portlet-app xmlns="http://java.sun.com/xml/ns/portlet
    /portlet-app_1_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:portlet="http://java.sun.com/xml/ns/portlet"
    xsi:schemaLocation="http://java.sun.com/xml/ns/portlet
    /portlet-app_1_0.xsd /opt/SUNWps/dtd/portlet.xsd" version="1.0">
        <portlet>
            <portlet-name>PrefPortlet</portlet-name>
            <portlet-class>examples.PrefPortlet</portlet-class>
            <expiration-cache>0</expiration-cache>
            <supports>
                <mime-type>text/html</mime-type>
                <portlet-mode>EDIT</portlet-mode>
                <portlet-mode>HELP</portlet-mode>
            </supports>
            <portlet-info>
                <title>PrefPortlet</title>
                <keywords>Hello, world, test</keywords>
            </portlet-info>
            <portlet-preferences>
                <preference>
                    <name>name</name>
                    <value>World</value>
                </preference>
            </portlet-preferences>
        </portlet>
    </portlet-app>
  2. Create the web.xml file. A web application also requires a web.xml file.

    If you have servlets for your portlet web application, then the servlet definition can be incorporated in the web.xml file.

    web.xml File for PrefPortlet


    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//
    DTD Web Application 2.3//EN" "http://java.sun.com/dtd/
    web-app_2_3.dtd">
    <web-app>
        <display-name>Portlet Examples</display-name>
    </web-app>
  3. Package everything into a WAR file.

    For the sample portlets, create an examples directory where all the files of the WAR will be placed. Then within the examples directory, create the WEB-INF directory. All the portlet files will be placed into the WEB-INF directory. For example, your directory hierarchy may look like this:


    examples/WEB-INF/
    		/web.xml
    		/portlet.xml
    		/classes/examples/PrefPortlet.class
  4. Create the WAR file. That is, change directories to examples and type the following command:


    jar -cvf examples.war *