Using Tomcat Ant tasks

Using Tomcat Ant tasks or using Ant to manage Tomcat, whatever you prefer. In the last post, about the directory structure of a web application, I found a little tricky to update the application every time I made changes on it. To reflect the changes on the browser, I had to stop the server, manually delete the deployed application from the webapps folder, install it again and then restart the server. Very tedious. Fortunately, Tomcat 6 includes a convenient set of tasks definitions for the Ant build tool which will help us with this managing tasks. Tasks such as deploy a new web application or undeploy an existing one without having to restart the server.

Usually, to work with this capabilities, is used a web application that Tomcat 6 includes installed by default on context path /manager. Here, we will not configure this web application, instead of that, we will configure the Ant build tool to have the same advantages than the web application manager offers.

Java EE Web application structure

In this post, we are going to create a simple Java EE Web application from the scratch. The goal of this example is to show the folder structure used in the development process of a Java EE Web application. The application will be deployed on Tomcat 6, we will use Ant to automatize all the processes implied (cleanup, delete & create folders, compile, etc). The folder structure used in this example is defined by Sun Microsystems on its guidelines.

The guidelines suggest where to place each type of file generally present in a Java EE Web application. In the example we will not use all these file types, but the conventions have a suggestion for almost every existing file, such as Ant files, classes, Java source files, deployment descriptors, test files, external libraries, javadoc files, Web application ARchive (WAR), etc. Why should we follow this guidelines? Organizing your application as shown in these post and in consequence as shown in the Sun guidelines will make easier to manage and maintain the project in the future, saving time and effort. Keep this into your head, respecting the predefined folder structure and placing the files where they belong helps other developers working on the project, who will immediately know where is each resource. Do it for your fellows!

Top