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:


2. MANIFEST.MF is a simple manifest file:

Manifest-Version: 1.0

3. would look like this:

package com.rebellisconsulting;
import javax.portlet.*;
public class HelloWorld extends javax.portlet.GenericPortlet {
        public void init() throws PortletException{
        public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
                // Set the MIME type for the render response
                // Display something

4. portlet.xml would look like this:

<?xml version="1.0" encoding="UTF-8"?><portlet-app xmlns="" version="2.0" xmlns:xsi="" xsi:schemaLocation="" id="com.rebellisconsulting.HelloWorld">        <portlet>
                <display-name xml:lang="en">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>

5. web.xml would look like this:

<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="3.0" xmlns="" xmlns:xsi="" xsi:schemaLocation="">        <display-name>HelloWorld</display-name>

6. Let's compile the HelloWorld. java:

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

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

You should have these directories and files now:

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!


Post a Comment

Popular posts from this blog

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

Creating a Custom WebSphere Portal 8 Theme with the Eclipse IDE