title: Including files in web.xml
body: <p>I'm in the process of writing unit tests for a JEE5 web service. The behaviour of the web service depends on the attributes set in the <code>web.xml</code> file. I'm wanting to therefore split my <code>web.xml</code> into a constant part and a part that is changed around inbetween test runs.</p>
  
  <p>To see if it's actually possible, I've tried to see if I can split out the <code>welcome-file-list</code> attribute. Using <a href="http://futurevsfantasy.livejournal.com/3626.html" rel="nofollow">some instructions I found</a> I've come up the following:</p>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/dtd/web-app_2_3.dtd" [
    &lt;!ENTITY fragment SYSTEM "fragment.xml"&gt;
  ]&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;com.sun.xml.ws.transport.http.servlet.WSServletContextListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;NewWebService&lt;/servlet-name&gt;
          &lt;servlet-class&gt;com.sun.xml.ws.transport.http.servlet.WSServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;NewWebService&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/NewWebService&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
    &amp;fragment;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>fragment.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;welcome-file-list&gt;
    &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  </code></pre>
  
  <p>However, I'm getting validation errors on the <code>web.xml</code> file:</p>
  
  <blockquote>
    <p>Attribute "version" must be declared for element type "web-app". [7]<br>
    Attribute "xmlns" must be declared for element type "web-app". [7]<br>
    Attribute "xmlns:xsi" must be declared for element type "web-app". [7]<br>
    Attribute "xsi:schemaLocation" must be declared for element type "web-app". [7]  </p>
  </blockquote>
  
  <p>I get the feeling that using a web app v2.3 DTD and a web app v2.5 schema inside the same file is the problem, but I don't know how I'm going to be able to get around it.</p>
  
  <p>(Any other approaches in splitting a web.xml file into smaller chunks would be welcome too!)</p>
  
  <p><strong>Update</strong></p>
  
  <p>If I remove the DTD reference like so...</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE web-app[
    &lt;!ENTITY fragment SYSTEM "fragment.xml"&gt;
  ]&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  etc, etc, etc.
  </code></pre>
  
  <p>...it appears as though the validation process ignores the <code>web-app_2_5.xsd</code> file:</p>
  
  <blockquote>
    <p>Element type "web-app" must be declared. [5]<br>
    Element type "listener" must be declared. [6]<br>
    Element type "listener-class" must be declared. [7]<br>
    Element type "servlet" must be declared. [9]<br>
    etc, etc, etc.  </p>
  </blockquote>