问题描述
我正在尝试在嵌入式模式下使用码头.初始化时出现以下错误:
I'm trying to use jetty in embedded mode. I'm getting the following error on initialization:
java.lang.NoSuchMethodError: javax.servlet.ServletContext.getJspConfigDescriptor()Ljavax/servlet/descriptor/JspConfigDescriptor;
at org.apache.jasper.servlet.TldScanner.scanJspConfig(TldScanner.java:148)
搜索了jetty 9.2.10.v20150310随附的所有jar,但没有找到任何相关类javax.servlet.ServletContext. servlet-api-3.1.jar中唯一的接口
Searched all the jars that ship with jetty 9.2.10.v20150310 but none but the class in question, javax.servlet.ServletContext, is not defined anywhere. Only interface in servlet-api-3.1.jar
我的启动代码:
public static void main(String[] args) throws Exception
{
JettyWebAppTest thiss = new JettyWebAppTest();
thiss.init();
}
private void init() throws Exception {
System.setProperty("java.io.tmpdir", "/tmp/bolek");
System.setProperty("org.apache.jasper.compiler.disablejsr199", "false");
Server server = new Server(8080);
WebAppContext context = new WebAppContext();
context.setResourceBase(<myresourcebase>);
context.setDescriptor("/WEB-INF/web.xml");
context.setContextPath("/");
context.setParentLoaderPriority(false);
context.setAttribute(
"org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/.*taglibs.*\\.jar$");
context.setAttribute("javax.servlet.context.tempdir",
System.getProperty("java.io.tmpdir"));
context.setAttribute("org.eclipse.jetty.containerInitializers",
this.jspInitializers());
context.setAttribute(InstanceManager.class.getName(),
new SimpleInstanceManager());
context.addBean(new ServletContainerInitializersStarter(context),
true);
context.setClassLoader(this.getUrlClassLoader());
context.addServlet(this.jspServletHolder(), "*.jsp");
server.setHandler(context);
server.start();
server.join();
}
private ServletHolder defaultServletHolder(URI baseUri)
{
ServletHolder holderDefault = new ServletHolder("default",
DefaultServlet.class);
holderDefault.setInitParameter("resourceBase",
baseUri.toASCIIString());
holderDefault.setInitParameter("dirAllowed", "true");
return holderDefault;
}
private List<ContainerInitializer> jspInitializers()
{
JettyJasperInitializer sci = new JettyJasperInitializer();
ServletContainerInitializer scii;
scii = (ServletContainerInitializer)sci;
ContainerInitializer initializer = new ContainerInitializer(scii, null);
List<ContainerInitializer> initializers = new ArrayList<ContainerInitializer>();
initializers.add(initializer);
return initializers;
}
private ClassLoader getUrlClassLoader()
{
ClassLoader jspClassLoader = new URLClassLoader(new URL[0], this.getClass().getClassLoader());
return jspClassLoader;
}
private ServletHolder jspServletHolder()
{
ServletHolder holderJsp = new ServletHolder("jsp", JettyJspServlet.class);
holderJsp.setInitOrder(0);
holderJsp.setInitParameter("logVerbosityLevel", "DEBUG");
holderJsp.setInitParameter("fork", "false");
holderJsp.setInitParameter("xpoweredBy", "false");
holderJsp.setInitParameter("compilerTargetVM", "1.7");
holderJsp.setInitParameter("compilerSourceVM", "1.7");
holderJsp.setInitParameter("keepgenerated", "true");
return holderJsp;
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
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"
version="3.0">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
推荐答案
您的类路径上具有一些不兼容的servlet api较旧版本.尝试从层次结构中的每个类加载器中打印出类路径.另外,请调查您的启动设置,以查看哪些jars被放置在运行时类路径上.
You have some incompatible, older version/s of the servlet api on your classpath. Try printing out the classpath from each of the classloaders in the hierarchy. Also investigate your startup setup to see which jars are being put on the runtime classpath.
Jan
这篇关于java.lang.NoSuchMethodError:javax.servlet.ServletContext.getJspConfigDescriptor与jsp一起使用嵌入式码头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!