Developing Web Applications With Ant by Richard Hightower - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Hello World Model 2 and J2EE

The following section explains techniques for using Ant to build and deploy J2EE applications. The Hello World example includes an applet, a Web application, an application, support libraries, and other components. This may be the only Hello World example that has an applet, servlet, and JSP and that attempts to be Model 2.

You're probably thinking, "Why should I implement the most complex Hello World application in the world?" This example--although a bit complex to just say "Hello World"--is as simple as possible while demonstrating how to build and deploy a J2EE application and its components with Ant. By working through this example, you will understand how to use Ant to build these different types of components and applications, and how to combine them by nesting build files.

The Model 2 HelloWorld example for this chapter is the simplest example of Model 2 architecture--also known as Model-View-Controller (MVC)--for JSP servlets. In this example, the applet and JSP are the View; the servlet is the Controller; and the object Model is a Java class.

The Web application build file is set up so that if we add one property, it can talk to the local implementation in the original model library (common code) defined earlier. The WebApplication directory holds HTML files, deployment descriptors, JSP files, and servlet Java source.

Because each component has its own set of deployment descriptors and configuration files, it makes sense to separate components into their own directories; this practice also makes it easier to reuse the components in other projects and applications. Each directory has its own Ant build file, which knows how to compile the components, package the binaries, and include the requisite configuration files (deployment descriptors and manifest files).

In the next section, we cover the Web application build fileā€”the heart of this example.