Java Web App Directory Layout
In order to get a Java web server or servlet container to run your Java web application, you need to package the resources inside it (servlets, JSP's etc.) in a standardized way. This text will show you how.
Here are the directories and files a web app should include:
The Root Directory
The root directory of you web application can have pretty much any name you want.
In the above example the root directory is called
Underneath the root directory, you can put all files that should be accessible in your web application. For instance, if your web application is mapped to the URL
... then the
index.jsp page will be accessible at the URL
If you create any subdirectories under the root directory, and place files in these subdirectories,
these will be available by the
subdirectory/file path, in the web application. For instance,
if you create a subdirectory called
layout, and put a file inside it called
then you could access that file from the outside, via this URL:
WEB-INF subdirectory is an exception from this rule, as I will describe below.
The WEB-INF Directory
WEB-INF directory is located just below the web app root directory.
This directory is a meta information directory. Files stored inhere are not supposed
to be accessible from a browser (although your web app can access them internally, in your code).
WEB-INF directory there are two important directories (
and one important file (web.xml). These are described below.
web.xml file contains information about the web application, which is used by the Java web server /
servlet container in order to properly deploy and execute the web application. For instance, the
contains information about which servlets a web application should deploy, and what URL's they should be mapped to.
I will not get into more detail about the
web.xml file here. Just know, that it exists.
classes directory contains all compiled Java classes that are part of your web application.
The classes should be located in a directory structure matching their package structure, just like if you
were to run them directly from the commandline, or package them in a JAR file.
lib directory contains all JAR files used by your web application. This directory most often
contains any third party libraries that your application is using. You could, however, also put your own classes
into a JAR file, and locate it here, rather than putting those classes in the