一尘不染

java.lang.NoSuchMethodError:javax.servlet.ServletContext.getJspConfigDescriptor与jsp一起使用嵌入式码头

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,但仅在任何地方都没有定义相关的类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>

阅读 864

收藏
2020-06-10

共1个答案

一尘不染

您的类路径上有一些不兼容的servlet
API较旧版本。尝试从层次结构中的每个类加载器中打印出类路径。还要调查您的启动安装程序,以查看将哪些jar放入运行时类路径。

一月

2020-06-10