Using the WAR Plug-in
Now that you have built the core subproject, you should move on to the web subproject. This is a good occasion for
you to learn how to use the Maven WAR plug-in. Figure 3-4 shows the directory
structure for the web
subproject.

Figure 3-4. Directory structure for the web subproject
A project that uses the WAR plug-in contains three source trees:
- src/main
Contains the runtime Java sources. There is only one servlet (
mdn.qotd.web.QuoteServlet) for thewebsubproject.- src/test
Contains the JUnit tests for unit testing the Java code found in src/main. The
mdn.qotd.web.QuoteServletTesttests methods from theQuoteServletservlet. Note that these unit tests are performed in isolation (i.e., without a running container). They are not functional tests.- src/webapp
Contains all the web application resources (HTML files, JSP files, configuration files, etc.). For the
websubproject you have only a WEB-INF/web.xml file, which maps theQuoteServletto a web context. This exceedingly simple web.xml file follows:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>QuoteServlet</servlet-name> <servlet-class>mdn.qotd.web.QuoteServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>MainServlet</servlet-name> <url-pattern>/</url-pattern> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access