Yes it is possible.
You can use xml entities
http://www.xml.com/pub/a/98/08/xmlqna2.html#ENTDECL
I don't know if there is a better syntax / way to do it, but this one has just worked for me (Tomcat 5)
This example declares an entity called "servlets" as coming from the file servletDefs.xml.
It gets included in web.xml with "&servlets;"
web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE webxmlspliiter [
><!ENTITY servlets SYSTEM "servletDefs.xml">
]>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
&servlets;
<error-page>
<error-code>404</error-code>
<location>/404Error.jsp</location>
</error-page>
</web-app>
servletDefs.xml
<servlet>
<servlet-name>MyJSP</servlet-name>
<jsp-file>/index.jsp</jsp-file>
<init-param>
<param-name>Param1</param-name>
<param-value>value1</param-value>
</init-param>
<init-param>
<param-name>Param2</param-name>
<param-value>value2</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyJSP</servlet-name>
<url-pattern>/MyJSP</url-pattern>
</servlet-mapping>
That at least will let you split up parts of your web.xml
Cheers,
evnafets
Its a new idea to me as well. I only read about XML entities the other day, and then this question pops up. It intrigued me enough to try it out.
>I'd still wonder if a huge web.xml is a sign that perhaps your Web app
>is trying to do too much. I'd be on the lookout for refactoring possibilities.
I would agree with you. I can't think of how you would get such a large web.xml that you couldn't deal with it easily.
I suppose it depends on your architecture. If you have 100 servlets to declare, you will end up with a large web.xml. Frameworks like struts/JSF just shift that configuration out of web.xml and into another xml configuration file. Some of those struts-config files can end up pretty large, even if you do split it into modules.