sparkyspider
sparkyspider

Reputation: 13529

Why, when working with Web Fragments to I get a "Premature End of File" error

I created 2 maven projects, a web application fxserver2 and a web library SleepyFox.

I then created a src/main/resources/META-INF/web-fragment.xml file in SleepyFox that I'd like to be automatically "included" into my fxserver web.xml

Unfortunately, I'm getting an error that looks like this:

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)

and then

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) 

The second error seems to indicate that the correct file is indeed being read, but I have no idea why its giving me a premature end of file error.

I included my fxserver2 web.xml

<?xml version="1.0"?>
<web-app>   
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

And also my SleepyFox web-fragment.xml

<web-fragment>
    <listener>
        <listener-class>com.foxbomb.fxserver2.ApplicationContext</listener-class>
    </listener>
</web-fragment>

Any advice greatly appreciated.

Upvotes: 3

Views: 14537

Answers (2)

Ravi Kadaboina
Ravi Kadaboina

Reputation: 8574

I think you need to mention the web-app_3_0.xsd schema in your main web.xml which also loads web-common_3_0.xsd automatically. This common schema has elements like 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">

Upvotes: 8

Jon Skeet
Jon Skeet

Reputation: 1502816

The first error makes it look like /Users/sparkyspider/Tomcat/apache-tomcat-7.0.12/conf/Catalina/localhost/fxserver2.xml either can't be found or is empty. (The "line 1 column 1" bit is what makes me think it's empty.) Make sure that file is present, has content, and has appropriate access rights so that it can be read.

Upvotes: 2

Related Questions