如果我将它部署到 Tomcat 或 Jboss 的部署文件夹中,我有一个可以正常工作的 Web 应用程序。我现在要做的是将此应用程序嵌入到 Jetty 容器中。我似乎无法让它工作,因为它吐出与 JSTL 标记库相关的错误。这是显示的错误:
Problem accessing /Web/app/localTimestamp. Reason:
/WEB-INF/views/localTimestamp.jsp(1,62) PWC6188: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
Caused by:
org.apache.jasper.JasperException: /WEB-INF/views/localTimestamp.jsp(1,62) PWC6188: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:92)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:378)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:172)
at org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:431)
at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:240)
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:502)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:582)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1652)
at org.apache.jasper.compiler.Parser.parse(Parser.java:185)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:244)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:145)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:212)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:625)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:575)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:485)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:537)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:412)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:271)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:98)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1157)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:927)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:575)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:485)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:519)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:412)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
at org.eclipse.jetty.server.Server.handle(Server.java:351)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:451)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:916)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:634)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:76)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:611)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:45)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534)
at java.lang.Thread.run(Thread.java:619)
我不明白为什么它无法获取 jstl jar 文件。这是Web应用程序的WEB-INF/lib文件夹中的jar文件
19/06/2012 14:54 62,983 activation-1.1.jar
19/06/2012 14:53 4,467 aopalliance-1.0.jar
19/06/2012 14:57 59,590 commons-fileupload-1.2.2.jar
19/06/2012 14:57 163,151 commons-io-2.1.jar
19/06/2012 14:54 207,723 commons-lang-2.1.jar
19/06/2012 14:53 60,686 commons-logging-1.1.1.jar
19/06/2012 14:54 104,172 jaxb-api-2.2.jar
19/06/2012 14:54 872,831 jaxb-impl-2.2.jar
19/06/2012 14:57 414,240 jstl-1.2.jar
19/06/2012 14:53 367,444 log4j-1.2.14.jar
19/06/2012 14:53 17,384 slf4j-api-1.5.2.jar
19/06/2012 14:53 9,501 slf4j-log4j12-1.5.2.jar
19/06/2012 14:53 331,474 spring-aop-3.1.0.RELEASE.jar
19/06/2012 14:53 53,079 spring-asm-3.1.0.RELEASE.jar
19/06/2012 14:53 589,253 spring-beans-3.1.0.RELEASE.jar
19/06/2012 14:53 829,601 spring-context-3.1.0.RELEASE.jar
19/06/2012 14:53 106,819 spring-context-support-3.1.0.RELEASE.jar
19/06/2012 14:53 442,400 spring-core-3.1.0.RELEASE.jar
19/06/2012 14:53 176,283 spring-expression-3.1.0.RELEASE.jar
19/06/2012 15:04 61,379 spring-oxm-3.0.6.RELEASE.jar
19/06/2012 14:53 246,036 spring-tx-3.1.0.RELEASE.jar
19/06/2012 14:53 540,819 spring-web-3.1.0.RELEASE.jar
19/06/2012 14:53 572,266 spring-webmvc-3.1.0.RELEASE.jar
19/06/2012 14:56 493,742 spring-ws-core-2.0.3.RELEASE.jar
19/06/2012 14:56 92,942 spring-xml-2.0.3.RELEASE.jar
19/06/2012 14:54 23,346 stax-api-1.0-2.jar
19/06/2012 14:56 148,522 wsdl4j-1.6.1.jar
19/06/2012 14:54 1,229,125 xercesImpl-2.9.1.jar
19/06/2012 14:55 109,318 xml-apis-1.0.b2.jar
这些是 Jetty 入门应用程序中包含的库:
16/07/2012 17:35 117,444 javax.el-2.2.3.jar
16/07/2012 17:35 38,863 javax.el-api-2.2.4.jar
16/07/2012 17:35 545,240 javax.servlet.jsp-2.2.3.jar
16/07/2012 17:35 53,124 javax.servlet.jsp-api-2.2.1.jar
16/07/2012 14:03 21,212 jetty-continuation-8.1.0.RC5.jar
16/07/2012 14:03 93,383 jetty-http-8.1.0.RC5.jar
16/07/2012 14:03 101,433 jetty-io-8.1.0.RC5.jar
16/07/2012 14:03 86,238 jetty-security-8.1.0.RC5.jar
16/07/2012 14:03 330,266 jetty-server-8.1.0.RC5.jar
16/07/2012 14:03 95,359 jetty-servlet-8.1.0.RC5.jar
16/07/2012 14:03 268,069 jetty-util-8.1.0.RC5.jar
16/07/2012 14:03 106,926 jetty-webapp-8.1.0.RC5.jar
16/07/2012 14:03 37,919 jetty-xml-8.1.0.RC5.jar
19/06/2012 14:57 414,240 jstl-1.2.jar
19/06/2012 14:53 367,444 log4j-1.2.14.jar
17/07/2012 09:42 6,300 WebJettyServices-0.0.1-SNAPSHOT.jar
16/07/2012 14:03 210,354 servlet-api-3.0.20100224.jar
17 File(s) 2,893,814 bytes
我认为该错误可能是由于 jar 文件中的冲突。我尝试了以下但没有成功
- 重建没有jstl依赖的war文件
- 在没有 jstl 依赖项的情况下重建了 Jetty Starter 应用程序。
- 在没有 jstl 依赖项的情况下重建两者
我现在卡住了,因为我不知道如何测试。以下是相关的代码片段。这是 Jetty 启动应用程序的 Maven pom 文件。我发现的一个大问题是很难真正知道需要哪些依赖项才能使其工作。search.maven.com 似乎没有 org.eclipse.* 依赖项所需的所有 jar 文件。
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>WebClient</artifactId>
<groupId>com.mypackage</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.mypackage</groupId>
<artifactId>WebJettyServices</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>WebJettyServices</name>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>8.1.0.RC5</jetty.version>
<log4j.version>1.2.14</log4j.version>
<glassfish.javax.version>2.2.3</glassfish.javax.version>
<glassfish.javax-impl.version>2.2</glassfish.javax-impl.version>
<glassfish.javax-jstl.version>1.2.1</glassfish.javax-jstl.version>
<glassfish.jstl.version>1.2</glassfish.jstl.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!--
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all-server</artifactId>
<version>8.1.0.RC5</version>
</dependency>
Jetty Webapp -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>
<!-- JSP Support -->
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp</artifactId>
<version>${glassfish.javax.version}</version>
</dependency>
<!-- EL Support -->
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>${glassfish.javax.version}</version>
</dependency>
<!-- JSTL Support -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${glassfish.jstl.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.mypackage.jetty.WebStarter</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
编辑
这是有问题的 JSP 页面
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="<c:url value="/styles/btmsm.css"/>"
type="text/css" />
<title>Local Timestamp</title>
</head>
<body>
<div id="container" style="width: 800px">
<div id="header" style="background-color: #EEEEBB;">
<h1 style="margin-bottom: 0;">Local timestamp</h1>
</div>
<div id="content"
style="background-color: #EEEEEE; height: 200px; width: 650px; float: left;">
The local time is ${localTime}
</div>
</div>
</body>
</html>
以及 web.xml 文件中显示的 Web 应用程序版本
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
如果我将 war 文件直接部署到 Tomcat 或 Jboss 部署文件夹中,则该应用程序确实可以工作。仅在嵌入 Jetty 时才会出现问题。