When you use WAR files to deploy applications on a Tomcat server, the structure of directories in a WAR file must conform to a specific standard. The directory of a web project contains various resources, such as application code, configuration files, and static files.
Structure of a project directory
To compile and package a project with ease, we recommend that you use the following structure to organize files in the project.
The src/main/java directory contains source Java class files. Each file forms part of an application. These source files are stored in the src/main/webapp/WEB-INF/classes directory and will be compiled into .class files that are accessible by an application. These .class files are stored in the webapp/WEB-INF/classes directory. Then, the webapp root directory that includes all files and subdirectories are packaged and deployed to a web server.
Structure of the webapp root directory
The webapp root directory contains resources, such as HTML files, JSP files, and static resources. These resources and the WEB-INF subdirectory will be packaged and deployed to a web server.
webapp ├── 404.jsp ├── WEB-INF ├── index.jsp └── static ├── css │ └── demoapp.css ├── fonts ├── images │ └── demoapp.png └── js └── bootstrap.min.js
Structure of the WEB-INF subdirectory
- The classes subdirectory that contains .class files. The .class files are compiled from the source application code that you develop.
- The lib subdirectory that contains various JAR files associated with the web application, for example, JAR files that contains database drivers.
- Web page template files, such as mustache files.
- A deployment descriptor file named web.xml.
WEB-INF ├── classes - A directory that contains compiled classes ├── lib - A directory that contains JAR libraries ├── views - A directory that contains Web page template files └── web.xml - A deployment descriptor file