我正在使用嵌入式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">