WAR Files

文章转载自:http://www.csse.monash.edu.au/courseware/cse3301/proj2004/davison2/war_files.htm

 

Basic Structure

A WAR file is just a zipped up directory designed to make deploying pakages easy.

To look into a WAR file, rename the extension to ".zip" and open it with WinZIP or something similar. (Another way of doing this if you deal with WAR files frequently in Windows is to create a new file association with your zip application).

Under Linux, you'lll have to rename the file (using mv), and then unpack the code with the "unzip" command (if it's installed).

The directory structure is fixed and must look like the following:

MyApplicationName
  |
  + --- WEB-INF
            |
            + --- classes

Your .jsp files should go into the root folder to be accessible. Any classes you have written that your JSP uses need to be stored in the classes directory. Be aware that if you have used packages, you will need to deploy the classes in the correct package path. For example if your package is called Andrew.3301, and your class is test.class, the path hierarchy looks like this:

MyApplicationName
  |
  + --- WEB-INF
            |
            + --- classes
                       |
                       + --- Andrew
                                |
                                + --- 3301
                                          |
                                          + --- test.class

Source Code

For convenience, you can deploy source in your WAR file in a src path as follows:

MyApplicationName
  |
  + --- src
  |
  + --- WEB-INF
            |
            + --- classes

This src directory is ignored by the deployed application.

It is important for this project that you put all of your source in this src directory so that I can read it.

Other Libraries

Deployed applications often require external libraries to work. A good example of this is database drivers. On a well deployed server you will have most of the common libraries available to your application by default.

In server environments where you are not sure what is available you are better off including these libraries in your WAR file. This means they will be bigger, slower to deploy and have a (slightly) longer start-up time, but you can be sure they will work. A good strategy is to include them all initially and then one-by-one remove them from your WAR to identify those libraries you need to deploy and those you don't.

The place to put libraries is in the lib path as illustrated below:

MyApplicationName
  |
  + --- src
  |
  + --- WEB-INF
            |
            + --- classes
            |
            + --- lib

posted on 2015-11-09 17:42  奈何作贼  阅读(230)  评论(0编辑  收藏  举报

导航