Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

A Practical Guide for Integrating EJB and Struts

EJB and the Struts framework each have received plenty of coverage individually, but what about leveraging EJB and Struts together? This tutorial lays out a complete step-by-step guide to integrating these two technologies.


advertisement
ou'll find plenty written about building and deploying EJB, and perhaps equally as much about building applications with the Struts framework. But what about leveraging EJB and Struts together? This tutorial lays out a complete step-by-step guide to integrating these two technologies, developing EJB components and incorporating them into Struts.

What You Need
JBoss 3.2.3
Eclipse 2.1.3
Jakarta Struts 1.1
Java 2 Platform, Standard Edition (J2SE 1.3+)

Installation
First, you need to download the necessary tools. Before anything else, make sure you have an installation of Eclipse. This article uses Eclipse 2.1.3.



Next, verify that your Eclipse installment is using the full JDK located at JAVA_HOME, not just the Java Runtime Environment (JRE):

  1. Go to Window -> Preferences, expand the Java node, and click Installed JRE.
  2. Click Add, and then click the Browse button for the JRE Home Directory. Go to your JAVA_HOME directory, and click OK.
  3. Type in JDK under JRE Name, and click OK. Make sure that JDK is checked and click OK to exit Windows -> Preferences (see Figure 1).
  4. Figure 1: Use the Full JDK Rather Than the JRE

Now, download the JBoss Plug-in:

  1. Open Eclipse. On the top menu, click Help->Software Updates->Find and Install.
  2. Select Search for new features to install and click Next.
  3. Click Add Update Site, and in the new box, type JBoss Plug-in under name and the URL http://jboss.sourceforge.net/jbosside/updates. The entry JBoss Plug-in (or whatever you entered under the text field name) now appears; make sure it is checked and click Next.
  4. You will now see a list of different JBoss-IDE versions. This tutorial uses version 1.2.3.
  5. Click Next, accept the license agreement, and install.

Next, download JBoss. For this tutorial, choose JBoss 3.2.3, the latest stable release at the time of this writing. Unzip the .zip file to your computer. Note that since JBoss 3.2.1, Tomcat has replaced Jetty as the default Web container.

To test if everything is in working order, go to the /bin directory of your JBoss installation, and execute the run.bat/run.sh that corresponds to your operating system. After the server tells you it has started, go to this URL in your browser: http://localhost:8080/jmx-console/index.jsp. You should see the JMX Management Console page, along with a JBoss logo on the right-hand side.

Finally, download the Jakarta Struts Framework and unzip the .zip file to your computer. (Struts 1.1 was the latest stable version at the time of this article.)

Okay! Now you are all set up and ready to rock and roll.

Create a Project
First create a Java Project in Eclipse:

  1. Click File -> New -> Project. Choose Java Project and click Next.
  2. Under Name, type StrutsEJBTutorial. Click Finish.

Import Struts
Now, incorporate Struts into your project. The easiest way is to import the struts-blank.war file:

  1. Right click on your project StrutsEJBTutorial in the package explorer of Eclipse.
  2. Select Import, then choose Zip file.
  3. Click browse and navigate to the location where you unzipped your Struts download. Once there, navigate to the /webapps directory.
  4. Under file name, type *.war and press enter. You should see a selection of war files. Choose struts-blank.war, press enter, and then click Finish (see Figure 2).

    Figure 2: Import a struts-blank.war File

Modify Project Properties
Now you are ready to modify your project properties:

  1. Right click on your project StrutsEJBTutorial in the package explorer of Eclipse.
  2. Select properties, and Click Java Build Path.
  3. Modify your source folder. For this tutorial, keep intact the directory structure of a Struts project. Click StrutsEJBTutorial and click Add Folder. Expand the WEB-INF node, then expand the src node, check java, and click OK. Make sure that WEB-INF and src are not checked; otherwise, Eclipse will try to recognize these as source folders as well.
  4. Modify your output folder. Click the Browse button on the bottom right, expand StrutsEJBTutorial and WEB-INF, and select classes. Click OK. Figure 3 displays a screenshot of how your source and output directories should look.

    Figure 3: Source and Output Directories
  5. Click the Libraries tab. Click Add JARs, and expand StrutsEJBTutorial, WEB-INF, and lib. Select all the jar files and click OK. Now click Add External JARs, and navigate to JBoss_directory/server/default/lib. Select jboss-j2ee.jar and javax.servlet.jar, click Open, and then click OK. Figure 4 shows the libraries you should include in your buildpath.

    Figure 4: Libraries in Your Buildpath



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap