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.

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 the web subproject.

src/test

Contains the JUnit tests for unit testing the Java code found in src/main. The mdn.qotd.web.QuoteServletTest tests methods from the QuoteServlet servlet. 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 web subproject you have only a WEB-INF/web.xml file, which maps the QuoteServlet to 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> ...

Get Maven: A Developer's Notebook 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.