为什么,当使用Web Fragments时,我收到"文件过早结束"错误

Spi*_*der 3 java tomcat servlet-3.0

我创建了2个maven项目,一个Web应用程序 fxserver2和一个Web库 SleepyFox.

然后我在SleepyFox中创建了一个src/main/resources/META-INF/web-fragment.xml文件,我希望将其自动"包含"到我的fxserver web.xml中

不幸的是,我收到的错误如下:

24-Jan-2012 19:38:50 org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor fxserver2.xml from /Users/sparkyspider/Tomcat/apache-tomcat-7.0.12/conf/Catalina/localhost
24-Jan-2012 19:38:50 org.apache.tomcat.util.digester.Digester fatalError
SEVERE: Parse Fatal Error at line 1 column 1: Premature end of file.
org.xml.sax.SAXParseException: Premature end of file.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
Run Code Online (Sandbox Code Playgroud)

然后

24-Jan-2012 19:38:50 org.apache.catalina.startup.ContextConfig parseWebXml
SEVERE: Parse error in application web.xml file at jndi:/localhost/fxserver2/WEB-INF/lib/SleepyFox-0.9.jar!/META-INF/web-fragment.xml
org.xml.sax.SAXParseException: Premature end of file.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) 
Run Code Online (Sandbox Code Playgroud)

第二个错误似乎表明正在读取正确的文件,但我不知道为什么它给我一个过早的文件错误结束.

我包含了我的fxserver2 web.xml

<?xml version="1.0"?>
<web-app>   
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>
Run Code Online (Sandbox Code Playgroud)

还有我的SleepyFox web-fragment.xml

<web-fragment>
    <listener>
        <listener-class>com.foxbomb.fxserver2.ApplicationContext</listener-class>
    </listener>
</web-fragment>
Run Code Online (Sandbox Code Playgroud)

任何建议都非常感谢.

Rav*_*avi 9

我想您需要在主web.xml中提及web-app_3_0.xsd模式,该模式还会自动加载web-common_3_0.xsd.此公共模式具有session-config>等元素

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
         http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
Run Code Online (Sandbox Code Playgroud)