Deploying web apps in Tomcat from the Command Line

You can move your WAR (Web Application Archive file) to Tomcat's webapps sub directory and leave there the WAR file, Tomcat will automatically extract it's contents and use them for the webapplication

You can create a WAR file from the command line. First change to the directory with the source files you want to compress into a WAR file, then type:

jar -cvf example.war *

Now you have your WAR file ready. Let's review the recommended WAR file directory structure

WAR file Standard Directory Layout

The following is the recommended struture for a WAR file this are the files and sub directories that should go in the root folder of the WAR:

*.html, *.jsp, etc. - The HTML and JSP pages, along with other files that must be visible to the client browser (such as JavaScript, stylesheet files, and images) for your application. In larger applications you may choose to divide these files into a subdirectory hierarchy, but for smaller apps, it is generally much simpler to maintain only a single directory for these files.

/WEB-INF - This dir must contain a fine named web.xml. this file can be used to configure the servlets and other components that make up the application. In addition, this dir is not directly accesible from the web.

/WEB-INF/web.xml - The Web Application Deployment Descriptor for your application. This is an XML file describing the servlets and other components that make up your application, along with any initialization parameters and container-managed security constraints that you want the server to enforce for you. This file is discussed in more detail in the following subsection.

/WEB-INF/classes/ - This directory contains any Java class files (and associated resources) required for your application, Servlet Classes and non-servlet classes, that are not combined into JAR files. If your classes are organized into Java packages, you must reflect this in the directory hierarchy under /WEB-INF/classes/. For example, a Java class named com.mycompany.mypackage.MyServlet would need to be stored in a file named /WEB-INF/classes/com/mycompany/mypackage/MyServlet.class.

/WEB-INF/lib/ - This directory contains JAR files that contain Java class files (and associated resources) required for your application, such as third party class libraries or JDBC drivers.

/META-INF - This dir contains the context.xml.file. Which can be used to configure the web app context.