java.lang.NoSuchMethodError: javax.servlet.ServletContext.getJspConfigDescriptor using embedded jetty with jsp
java.lang.NoSuchMethodError: javax.servlet.ServletContext.getJspConfigDescriptor using embedded jetty with jsp
我正在尝试在嵌入式模式下使用码头。我在初始化时遇到以下错误:
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,但 none 但有问题的 class javax.servlet.ServletContext 未在任何地方定义。只有 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>
您的类路径中有一些不兼容的旧 version/s servlet api。尝试打印出层次结构中每个类加载器的类路径。还要调查您的启动设置以查看将哪些 jar 放在运行时类路径中。
一月
在 Java 构建 Path/Libraries/Groovy 库中指定 "No" 以包含 Groovy lib 文件夹中的所有 jar。
进行此更改并 "finish"。
注意:如果您再次打开此对话框,您仍会看到 "yes" 被选中。忽略那个。
我正在尝试在嵌入式模式下使用码头。我在初始化时遇到以下错误:
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,但 none 但有问题的 class javax.servlet.ServletContext 未在任何地方定义。只有 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>
您的类路径中有一些不兼容的旧 version/s servlet api。尝试打印出层次结构中每个类加载器的类路径。还要调查您的启动设置以查看将哪些 jar 放在运行时类路径中。
一月
在 Java 构建 Path/Libraries/Groovy 库中指定 "No" 以包含 Groovy lib 文件夹中的所有 jar。
进行此更改并 "finish"。
注意:如果您再次打开此对话框,您仍会看到 "yes" 被选中。忽略那个。