Placing Java Class Files in the Right Directory

The WEB-INF directory contains files and subdirectories for other types of resources used by the application. Files under this directory aren’t directly accessible to a browser. Two WEB-INF subdirectories have special meaning: lib and classes. The lib directory contains JAR files with Java class files, for instance JavaBeans classes, custom action handler classes, and utility classes. The classes directory contains class files that are not packaged in JAR files. The web application has access automatically to all class files in the lib and classes directories (in other words, you do not have to add them to the CLASSPATH environment variable).

If you store class files in the classes directory, they must be stored in subdirectories mirroring the package structure. For instance, if you have a class named com.mycorp.util.MyUtils, you must store the class file in WEB-INF/classes/com/mycorp/util/MyUtils.class. Another type of file that can be stored in the classes directory is the type of a resource properties file used by the PropertyResourceBundle class, as described in Chapter 14.

The WEB-INF directory can also contain other directories. For instance, a directory named tlds is by convention used for tag library Tag Library Descriptor (TLD) files when they are not packaged in JAR files.

During development it’s more convenient to work with the web application files in a regular filesystem structure instead creating a new WAR file every time ...

Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.