Creating Portlets without RAD (IBM WebSphere Portal 8)

This question comes up a lot... Is there any way to create portlets for IBM WebSphere Portal if I do not have RAD available? 
Rational Application Developer is the IDE of choice for IBM WebSphere Portal developers. There are a lot of advantages of using RAD for portal development (see link above for tech specs). There is a 30 days trial available for download if you would like to try it and great news for all the Apple fans:), it now works on Mac OS.

However, IBM is showing you how to create a portlet form the command line: Creating a simple portlet. Compiling would require a few Portal libraries. So if you have a portal install available and would like to give it a try, follow the following steps. This is a cheat sheet to the already existing IBM documentation above:

Note: I am assuming that you are on Linux machine and there is a Portal v8 installed. Hard core portal developers that do not need all the bell and whistles of RAD can use the light weight Eclipse IDE (configure the Build Path to include the required libraries required for compilation and create some custom Run Configuration to automate the deployment). 

1. Create the directories structure and files for your future HelloWorld portlet:

META-INF/MANIFEST.MF 
WEB-INF/classes/com/rebellisconsulting/HelloWorld.java
WEB-INF/portlet.xml
WEB-INF/web.xml


2. MANIFEST.MF is a simple manifest file:

Manifest-Version: 1.0
Class-Path:

3. HelloWorld.java would look like this:

package com.rebellisconsulting;
import java.io.*;
import javax.portlet.*;
public class HelloWorld extends javax.portlet.GenericPortlet {
        public void init() throws PortletException{
                super.init();
        }
        public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
                // Set the MIME type for the render response
                response.setContentType(request.getResponseContentType());
                // Display something
                response.getWriter().println("HelloWorldPortlet#doView()");
        }
}

4. portlet.xml would look like this:

<?xml version="1.0" encoding="UTF-8"?><portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" id="com.rebellisconsulting.HelloWorld">        <portlet>
                <portlet-name>HelloWorld</portlet-name>
                <display-name xml:lang="en">HelloWorld</display-name>
                <display-name>HelloWorld</display-name>
                <portlet-class>com.rebellisconsulting.HelloWorld</portlet-class>                <init-param>                        <name>wps.markup</name>                        <value>html</value>                </init-param>                <expiration-cache>0</expiration-cache>
                <supports>                        <mime-type>text/html</mime-type>                        <portlet-mode>view</portlet-mode>
                </supports>                <supported-locale>en</supported-locale>
                <portlet-info>                        <title>HelloWorld</title>                        <short-title>HelloWorld</short-title>                        <keywords>HelloWorld</keywords>                </portlet-info>        </portlet>
</portlet-app>


5. web.xml would look like this:

<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">        <display-name>HelloWorld</display-name>
</web-app>

6. Let's compile the HelloWorld. java:

Set the CLASSPATH for the compiler:
. /opt/IBM/WebSphere/PortalServer/bin/setupCmdLine.sh 

Go inside the WEB-INF/classes/com/rebellisconsulting directory and execute:

/opt/IBM/WebSphere/AppServer/java/bin/javac -classpath /opt/IBM/WebSphere/PortalServer/doc/compile/portletapi_20.jar HelloWorld.java

You should have these directories and files now:
META-INF/MANIFEST.MF
WEB-INF/classes/com/rebellisconsulting/HelloWorld.java
WEB-INF/classes/com/rebellisconsulting/HelloWorld.class
WEB-INF/portlet.xml
WEB-INF/web.xml

7. Package the portlet into a WAR archive:
/opt/IBM/WebSphere/AppServer/java/bin/jar -cf HelloWorld.war META-INF WEB-INF

8. Deploy your portlet via GUI or use XMLAccess. 

9. Voila!



Comments

Post a Comment

Popular posts from this blog

Ant Example: Check if a directory is empty or if specific file exists.

Django (1.2.3) CRUD Using Generic Views

Creating a Custom WebSphere Portal 8 Theme with the Eclipse IDE