Building and Deploying an EAR - Common JAR
(Page 3 of 4 )
In the previous chapter, we created a CarBean POJO to hold the various attributes of a car. We stored it in the WAR file because, well, you didn’t have any other choice at that time. We should now reconsider the storage location for the CarBeanto maximize its reuse.
By the end of this book, we will pull cars out of a database in the persistence tier, and hand them to objects in the business tier, which ultimately will pass them up to the presentation tier. An object that is shared across tiers is a perfect candidate for the Common JAR.
In addition to custom domain objects, the Common JAR is a great location to store common libraries such as Log4J or JDOM. While both WARs and EJB JARs have lib directories, they are best used for tier-specific libraries. For example, the JSTL JARs belong in the WAR—they have no other purpose than to support the creation of web pages. On the other hand, logging is something that happens throughout the codebase—it really belongs in a common JAR.
Let’s factor ourCarBean out of the WAR and into the Common JAR. In addition to moving directories, we’re going to rename it to better describe its purpose in the application.
The suffix “Bean” is a bit overloaded: it includes JavaBeans, Enterprise Java Beans, Session Beans, Message-Driven Beans, JMX MBeans, and the list goes on. The design pattern that best describes theCarBean’s function is a Data Transfer Object (DTO), so when we move the bean, we’ll also rename itCarDTO. The source code will remain the same, but the name will give us a better idea about the true purpose of the class.
Next: Exploring the New Directory Structure >>
More Web Authoring Articles
More By O'Reilly Media
|
This article is excerpted from chapter 3 of the book JBoss at Work: A Practical Guide, written by Tom Marrs and Scott Davis (O'Reilly; ISBN: 0596007345). Check it out today at your favorite bookstore. Buy this book now.
|
|