2012-02-19 75 views
5

我正在使用嵌入式Jetty啓動webapp,並將JSP頁面用作視圖。使用JSP使用嵌入式Jetty會出現錯誤「web-jsptaglibrary_1_2.dtd not found」

使用maven-jetty-plugin可以很好地進行測試,這讓我覺得在引導服務器時(以及哪些是問題的根本原因)我缺少一些依賴關係。

我引導碼頭用命令:

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

我已經使用Maven的依賴插件一定要得到的類路徑上的所有DEPS(打包的戰爭文件外):

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

主類看起來是這樣的:

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

嵌入式Jetty服務器沒有錯誤開始,BU t導航到返回JSP頁面的URL時,我總是得到這個錯誤。

堆棧跟蹤:

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) 

我用碼頭8,我的web.xml文件中配置的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"> 

回答

6

我發現丟失的dtd文件的問題是我需要Jetty JSP JAR。

我使用這些依賴於JSP的支持時,它沒有工作:

<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> 

碼頭亞軍總是爲我工作,所以我看着那隻罐子文件的依賴關係。

<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> 

在javax.servlet.jsp依賴缺少DTD的文件存在,所以這個問題就走了,當我開始使用它們。

所以我想問題是我需要Jetty特定的JSP依賴關係而不是普通的依賴關係。任何人都可以解釋爲什麼Jetty是這樣實現的嗎?

相關問題