我试图在嵌入模式下使用jetty。我在初始化时遇到以下错误:
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一起发布的罐子,但除了有问题的类之外,没有任何一个,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>
答案 0 :(得分:1)
您的类路径上有一些不兼容的旧版本的servlet API。尝试从层次结构中的每个类加载器打印出类路径。还要调查您的启动设置,以查看哪些jar放在运行时类路径上。
扬
答案 1 :(得分:0)
在Java Build Path / Libraries / Groovy Library中,指定“否”以包含来自Groovy lib文件夹的所有jar。
进行此更改并“完成”。
注意:如果再次调出此对话框,您仍会看到选中“是”。忽略这一点。