Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using embedded Jetty using JSP gives error "web-jsptaglibrary_1_2.dtd not found"

I am using embedded Jetty to launch a webapp and I use JSP pages as views.

Using the maven-jetty-plugin works fine for testing, which makes me think I am missing some dependencies when bootstrapping the server (and which is the root cause of the problem).

I bootstrap Jetty with command:

java $JAVA_OPTS -cp target/classes:target/dependency/* xxx.Main

I have used the dependency plugin in Maven to be sure to get all deps on the classpath (outside the packaged war-file):

<execution>
<id>copy-dep</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>

The Main class looks like this:

      Server server = new Server(8080);
    WebAppContext root = new WebAppContext();
    root.setContextPath("/");
    root.setWar("target/app.war");
    server.setHandler(root);
    server.start();
    server.join();

The embedded Jetty server starts without errors, but when navigating to the URL that returns the JSP page I always get this error.

The stacktrace:

PWC6181: File /javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd not found

Caused by:

org.xml.sax.SAXException: PWC6181: File /javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd not found
at org.apache.jasper.xmlparser.MyEntityResolver.resolveEntity(ParserUtils.java:566)
at com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(EntityResolverWrapper.java:107)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntityAsPerStax(XMLEntityManager.java:1018)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1192)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1090)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1003)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at org.apache.jasper.xmlparser.ParserUtils.parseXMLDocument(ParserUtils.java:296)
at org.apache.jasper.xmlparser.ParserUtils.parseXMLDocument(ParserUtils.java:366)
at org.apache.jasper.runtime.TldScanner.scanTld(TldScanner.java:526)
at org.apache.jasper.runtime.TldScanner.scanJar(TldScanner.java:379)
at org.apache.jasper.runtime.TldScanner.scanJars(TldScanner.java:607)
at org.apache.jasper.runtime.TldScanner.scanTlds(TldScanner.java:282)
at org.apache.jasper.runtime.TldScanner.getLocation(TldScanner.java:255)

I use Jetty 8 and my web.xml is configured for Servlet 3.0.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
like image 1000
Daniel Avatar asked Feb 19 '12 15:02

Daniel


1 Answers

I found out that the problem with the missing dtd-file was that I needed Jetty JSP JARs.

I was using these dependencies for JSP-support when it did not work:

<dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.2</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jsp-impl</artifactId>
        <version>2.2</version>
    </dependency>

Jetty-runner always worked for me so I looked at the dependencies in that jar-file.

<dependency>
    <groupId>org.eclipse.jetty.orbit</groupId>
    <artifactId>javax.servlet.jsp</artifactId>
    <version>2.2.0.v201112011158</version>
</dependency>
<dependency>
    <groupId>org.eclipse.jetty.orbit</groupId>
    <artifactId>org.apache.jasper.glassfish</artifactId>
    <version>2.2.2.v201112011158</version>
</dependency>

In the javax.servlet.jsp dependency the missing dtd-files exist, so the problem went away when I started using them.

So I guess the problem was that I needed the Jetty specific JSP dependencies and not the general ones. Can anyone explain why Jetty is implemented that way?

like image 198
Daniel Avatar answered Oct 14 '22 21:10

Daniel