Login | Register   
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 : Page 5

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
Create a Merge Directory
Before you generate your Web deployment descriptors, you should create a merge directory and split up the original web.xml that came with the struts-blank.war import. To do so, create several XML files. When you run XDoclet, it will take these other XML files and re-generate web.xml. Alternatively, you can simply generate the web.xml entries in another file, and then paste them into your original web.xml. However, for a longer-term solution that eliminates the need to continually copy and paste these entries, I recommend creating the merge directory and splitting up the original web.xml:
  1. Create a new directory called merge under your project root.
  2. Create a servlet-mappings.xml file under the merge directory and enter the following:

    <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>

  3. Create a servlets.xml file under the merge directory and enter the following:

    <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>2</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet>

  4. Create a taglibs.xml file under the merge directory and enter the following:


    <taglib> <taglib-uri>/tags/struts-bean</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-html</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-logic</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-nested</taglib-uri> <taglib-location>/WEB-INF/struts-nested.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-tiles</taglib-uri> <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location> </taglib>

  5. Create a welcomefiles.xml file under the merge directory and enter the following:

    <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list>

Create Application.xml File
You also need to deploy an application.xml file with your .ear file. Create one under your /META-INF directory:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd"> <application> <display-name>Stock Application</display-name> <module> <ejb>StockEJB.jar</ejb> </module> <module> <web> <web-uri>StockWeb.war</web-uri> <context-root>/stock</context-root> </web> </module> </application>

Generate Web Deployment Descriptors
Now you are ready to generate web.xml and jboss-web.xml with XDoclet:

  1. Right click on your project StrutsEJBTutorial in the package explorer. Click properties, and then click XDoclet Configurations.
  2. Right click in the upper white space area on the right-hand side, and click Add. A popup telling you to enter a configuration name will appear. Type Web and click OK.
  3. Make sure Web is highlighted in the upper box, and right click in the lower left white space. Select webdoclet and click OK.
  4. Make sure that webdoclet is checked. Now check the box for destDir and set the value to WEB-INF. Next, check mergeDir and set that value to merge (see Figure 12).

    Figure 12: Add webdoclet to the Web Configuration
  5. Right click webdoclet in the left white box. Click Add, choose deploymentdescriptor, and click OK. Now select deploymentdecriptor (you may have to expand the webdoclet node if you don't see it), check destDir, and set the value to WEB-INF. Next, check mergeDir and set that value to merge (see Figure 13).

    Figure 13: Add deploymentdescriptor to the webdoclet
  6. Right click webdoclet. Click Add, choose jbosswebxml, and click OK. Select jbosswebxml, make sure destDir is checked, and set the value to WEB-INF. Set Version to 3.0 and check it. Click OK (see Figure 14).

    Figure 14: Add jbosswebxml to the webdoclet
  7. Right click webdoclet. Click Add, choose fileset, and click OK. Select fileset, make sure destDir is checked, and set the value to WEB-INF/src/java. Uncheck excludes. Next, make sure includes is checked and set the value to lum/webdoclet/WebDoclet.java. Click OK (see Figure 15).

    Figure 15: Add fileset to the webdoclet
  8. Now, click OK at the bottom right corner. Eclipse will generate an xdoclet-build.xml file. To run your XDoclet file, right click on your project StrutsEJBTutorial in the package explorer, and then click Run XDoclet.
  9. You will see that XDoclet generated both your Web deployment descriptors, web.xml and jboss-web.xml, in your /WEB-INF directory. You'll also notice that XDoclet used the various XML files in your /merge directory to recreate your original web.xml file.



Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap