Introducing Rational Application Developer

Build J2EE applications quickly

IBM Rational Application Developer is a re-branding of IBM WebSphere Studio Application Developer. This article introduces Rational Application Developer and shows how it simplifies Java 2 Enterprise Edition (J2EE) development. It also shows how to build a Java class and a simple Struts-based J2EE application. Follow-up articles will elaborate in more detail on what is covered in this introductory article.

Share:

Kunal Mittal (kunal@kunalmittal.com), Portal/J2EE Architect, Freelance Developer

Kunal MittalKunal Mittal is a consultant specializing in Java™, Java 2 Platform, Enterprise Edition (J2EE), and Web services technologies. He is the co-author of and has contributed to several books on these topics. Kunal is currently working on a portal project for Sony Pictures Entertainment. For more information, visit his Web site at http://www.soaconsultant.com.



19 July 2005

Also available in Russian

Note: The IBM Rational Software Development Platform is an Eclipse-based common development environment that is shared by the following products:

  • IBM® Rational® Web Developer
  • IBM® Rational® Application Developer
  • IBM® Rational® Software Modeler
  • IBM® Rational® Software Architect
  • IBM® Rational® Functional Tester
  • IBM® Rational® Performance Tester

If you've installed Rational Software Architect, you have a full version of Rational Application Developer.

In a nutshell, Rational Application Developer is the re-branding of WebSphere Studio Application Developer. IBM built WebSphere Studio Application Developer on top of Eclipse -- an open source project to develop an open, extensible, integrated development environment (IDE) -- and customized it for J2EE development specifically for WebSphere. With the acquisition of the Rational family of products, IBM has now extended WebSphere Studio Application Developer and the Rational portfolio to include a fully integrated family of products, the IBM® Rational® Software Development Platform, that allow developers and project teams to collaborate on the entire project life cycle.

What's new in Rational Application Developer?

So, is WebSphere Studio Application Developer dead? Not really. All the WebSphere Studio Application Developer features, such as extended support for the WebSphere platform, are still available as part of Rational Application Developer. Rational Application Developer is a comprehensive IDE that enables you to quickly design, develop, analyze, test, profile, and deploy Web, Web services, portal, Java, and Java? 2 Platform, Enterprise Edition (J2EE?) applications. It provides you with sophisticated static code visualization tools and is capable of supporting multi-vendor runtime environments, but is optimized for WebSphere Software. Note: When you download Rational Application Developer (see Resources for more information), you have the option to download several toolkits as add-ons as well, including a toolkit that you can use to view and analyze production data.


Create the HelloWorld class in Rational Application Developer

Let's dive in. Open Rational Application Developer, then switch to the Java perspective by selecting Window > Open Perspective > Java. Next, create a Java project. (For now, you can use the default settings.) Figure 1 shows the Java perspective in Rational Application Developer.

Figure 1. Create a Java project in Rational Application Developer
Create a Java project in Rational Application Developer

Create a new class by right-clicking the source folder and selecting New > Class. The New Java Class Wizard appears to help you set up various options about your class (see Figure 2).

Figure 2. Set options for a new Java class
Set options for a new Java class

Enter HelloWorld in the Name text box, then choose the options appropriate to your environment. I recommend selecting the public static void main(String[] args) option, which Figure 2 shows, to generate a "main" method in the resulting Java class. (Notice the Interfaces text area, in which you can enter any interface you want this class to implement. For example, if you're writing a Java Bean and want to implement Serializable, you can use this option to specify that.)

After you've completed the wizard, switch to the Package Explorer. There you'll find the class you've just created and can view the code, which Listing 1 shows. Add one line of code to the main method that prints "Welcome to Rational Application Developer."

Listing 1. Code for the newly created HelloWorld class
/*
 * Created on May 5, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author Kunal Mittal
 *
 * TODO To change the template for this 
 * generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class HelloWorld {

      public static void main(String[] args) {

        System.out.println("Welcome to Rational Application Developer ");
      }
}

The cool part is that you can actually compile and execute this code right from Rational Application Developer. Select Run > Run As > Run As Java Application to see the code compile and execute. You can view the output of the code in the Console window.

In addition, you can choose to run the code in Debugger mode so that you can step through your code. This functionality is of little value for a simple application like HelloWorld, but it's of immense value when you start building real applications using this tool. (Debugger support is a topic for another article, so I don't try to cover it here.)


Create a simple Struts-based application

Now, I'll show you how to create a simple Struts-based application using Rational Application Developer. Struts is a Model-View-Controller (MVC) framework that is fast becoming the standard in J2EE Web development. Struts provides a clean separation between the View (JavaServer Pages, or JSP) layer of the application, the Controller (Action classes), and the Model layer (such as Data Access Objects (DAOs) and Enterprise JavaBean (EJB) technology). For more information about Struts, see Resources.

Begin by creating a new Dynamic Web Project. When the New Dynamic Web Project Wizard appears, you can, for the most part, leave the default options. All you're doing is specifying a name for your Web application, setting the compliance level to the Servlet specification, and identifying the server you want to deploy to. Figure 3 shows the options that you should select.

Figure 3. Create a new Dynamic Web Project
Create a new Dynamic Web Project

In the second window of the wizard (see Figure 4), select the Struts and JSP Tag Libraries options, then click Finish.

Figure 4. Features of a Dynamic Web Project
Features of a Dynamic Web Project

Create a new Web diagram. (You build this diagram as you build all the code for this application.) Right-click in the Web diagram, then select New > Action Form Bean. Complete the wizard to quickly create your Form Bean. Then, create a simple CustomerBean with two attributes: firstName and lastName. The code is shown in Listing 2.

Listing 2. Code to create CustomerBean
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

/**
 * Form bean for a Struts application.
 * Users may access 2 fields on this form:
 * @version 1.0
 * @author Kunal Mittal
 */
public class CustomerBean extends ActionForm

{

    private String firstName = null;

    private String lastName = null;

    /**
     * Get firstName
     * @return String
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Set firstName
     * @param String
     */
    public void setFirstName(String f) {
        this.firstName = f;
    }

    /**
     * Get lastName
     * @return String
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Set lastName
     * @param String
     */
    public void setLastName(String l) {
        this.lastName = l;
    }

    /**
     * Constructor
     */
    public CustomerBean() {

    }

    public void reset(ActionMapping mapping, 
                 HttpServletRequest request) {

        // Reset values are provided as samples only. 
        // Change as appropriate.

        firstName = null;
        lastName = null;

    }

    public ActionErrors validate(ActionMapping mapping,
            HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();
        // Validate the fields in your form,
        // adding each error to this.errors as found, e.g.,

        // if ((field == null) || (field.length() == 0)) {
        //   errors.add("field", new org.apache.struts.action.ActionError("error.field.required"));
        // }
        return errors;

    }
}

Now, in Rational Application Developer, create a JSP file. To do so, right click in the Navigator view, then select New > JSP. Complete the wizard, which is similar to the wizard you used to create a new Java class. Be sure to select Struts JSP from the Model drop-down list, specify the URL mappings, and select the CustomerBean. The wizard creates a JSP file that allows you to get data from this Form Bean. Listing 3 shows the code for this file.

Listing 3. firstPage.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<html:html>
<HEAD>
<%@ page language="java" contentType="text/html; 
         charset=ISO-8859-1"%>
<LINK href="theme/Master.css" rel="stylesheet"
        type="text/css">
<TITLE>firstPage.jsp</TITLE>
</HEAD>

<BODY>
<html:form action="firstPage" method="post" enctype="text/plain">
<TABLE border="0">
    <TBODY>
        <TR>
            <TH>firstName</TH>
            <TD><html:text property="firstName" /></TD>
        </TR>
        <TR>
            <TH>lastName</TH>
            <TD><html:text property="lastName" /></TD>
        </TR>
        <TR>
            <TD>
               <html:submit property="submit" value="Submit" />
            </TD>
            <TD><html:reset /></TD>
        </TR>
     </TBODY>
</TABLE>
</html:form>
</BODY>
</html:html>

Define a server to which you'll deploy this code. For this example, I downloaded and installed Tomcat Version 5.0. Create a new server entry, and set the defaults for Tomcat (see Figure 5).

Figure 5. Specify a server for your Web project
Specify a server for your Web project

Finally, run the application on the server. In the Navigator view, right-click the Web application, then select Run > Run on Server. Figure 6 shows the execution of this simple application.

Figure 6. Testing your Web application
Testing your Web application

That's how quick it is to create a simple Struts-based application in this tool. Explore this functionality further to add validation to this simple application.


Summary

In this article, I introduced Rational Application Developer, a re-branding of WebSphere Studio Application Developer that allows more integration with Rational Software Modeler and Rational Software Architect. I also illustrated how to create simple Java code and a Struts-based Web application quickly and deploy them from within Rational Application Developer. I used Apache Tomcat as the deployment container for the simple Struts application, but you could deploy the application on a machine running WebSphere or use the BEA WebLogic Platform toolkit to deploy to WebLogic. With Rational Application Developer, you see how you can quickly develop, deploy, and test Java or J2EE applications.

Resources

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Rational software on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=88699
ArticleTitle=Introducing Rational Application Developer
publish-date=07192005