Home  > Resources  > Blog

Struts 2 Project Template for RAD 7.5

 
March 31, 2011 by Bibhas Bhattacharya
Category: WebSphere

Rational Application Developer (RAD) 7.5 supports only up to Struts 1.3. I do not anticipate IBM to support Struts 2.0 any time soon.

Adding Struts 2.0 to a web project is not rocket science but it can take up a bit of time. You need to assemble the right JAR files and create struts.xml in the right place and what not. I have created a template project file that will avoid a lot of headache and you can be up and running with Struts 2.0 in no time.

Download Stuts2Template.zip

Features of the Template Project

The dynamic web project is for Servlet 2.5 (or Java EE 5) spec. By default, Struts2 distribution uses Servlet 2.4 spec. I changed the web.xml to use the new version.

The project uses WebSphere Application Server 7.0 as the target runtime.

Using the Template Project

You should be able to create a new dynamic web project from the template very easily. Just follow these steps.

1. Launch RAD 7.5.

2. From the menubar, select File > Import. Expand Other and select Project Interchange.

3. Click Next.

4. Import the Struts2Template from the downloaded ZIP file.

5. You need to rename the project to something more suitable. Right click the project and select Refactor > Rename. Enter a different name and click OK.

RAD does not allow you to deploy a web project directly to a test server. You need to create an enterprise application project and add the Struts2 web project to it. Follow these steps.

6. From the menubar, select File > New > Enterprise Application Project.

7. Enter a project name. Click Next.

8. Select the Struts2 web project.

9. Click Finish.

That’s it. You should do a quick test to make sure that things are in order.

Validating the Project

1. Start the server if it is not running.

2. Add the enterprise application project to the server.

3. There is an index.html file in the Struts2 project. Right click it and select Run As > Run on Server.

4. Click the Hello World link. You should see the Hello World page.

Understanding the Project Structure

The WebContent/WEB-INF/lib folder contains a minimal set of JAR files needed by Struts2.

Under Java Resources/src folder, you will see the struts.xml file.  After the project is built, RAD copies all .class files and any other files from the source folder to WEB-INF/classes. You should never directly edit files in the classes folder.

A sample action class is provided as com.webage.struts.HelloWorld. The action is registered in struts.xml.

Follow Us

Blog Categories