Deploying Applications

I have touched on this area in a number of my other features, so take a look at how each application server deploys its web apps (see below links), in this feature I will be using Tomcat

In the feature I will be answering three main issues

Most deployments tools (Sun Java studio, Eclipse, Ant, etc) will know where to place files (after you have configured it) but if you are system/application administrator you need to have an idea of the files and directory layout, most application servers follow the same pattern but they do have slight differences.

With Tomcat you will have a top level directory called something like c:\tomcat6 (remember when you install Tomcat try to have no spaces in the directory name), underneath this directory you will have a directory called webapps, this is where you will deploy your application.

Depending on how you deploy you application it will either have a WEB-INF or a META-INF or both, I suggest you take a look at my Tomcat web config feature to understand what they do and when you should use them. One note to remember is that both the META-INF and the WEB-INF are private to the Container can cannot be accessed by a web browser, this includes other WEB-INF/META-INF directories located in JAR files as well.

I have a detailed picture below that displays how a fairly complex application may be setup

A note worth remembering is that the Container will always look for classes inside WEB-INF/classes before it looks inside JAR files in WEB-INF/lib

WAR Files

A Web ARchive file is a snapshot of your web app structure in a compressed form (its really a JAR file but with the .jar extension changed to a .war extension). In Tomcat (may not be the same in other app servers) the name of the WAR file becomes the web app name, for example if you deploy a CoffeeApp.war file, the name of the application will be CoffeeApp. The only difference in a WAR than the picture above is a new META-INF directory, this is used to declare library dependencies using a file called MANIFEST.MF, this file is used to check the dependencies before a user uses your application and experiences problems. I have more information about WAR files in my Tomcat web config feature.

Welcome and Error Page Files

It is always good idea to have a default page for your entire web site, this is called a welcome page. You can tell the Container to look for default web page files in a specific order, remember though that if either of these files is not in the specific URL then you will obtain a file listing by default other application servers may produce a "404 Not Found error".

welcome files in the DD (web.xml) <web-app ...>

You can also configure error pages within your application, this gives a more friendly feel to your web site if things do go wrong and you can be specific on the type of error. One thing to remember is that you must use the fully-qualified class name.

error pages in the DD (web.xml) <web-app ...>



Mime Mapping

You can configure a mapping between an extension and a mime type in the DD

mime mapping <mime-mapping>