我正在尝试创建一个简单的jetty服务器/容器,它将接受war文件并进行部署。这不是带有弹簧引导的嵌入式码头。
下面是我的build.gradle依赖关系:
dependencies {
def jettyVersion = "9.4.34.v20201102"
implementation "org.eclipse.jetty:jetty-server:$jettyVersion"
implementation "org.eclipse.jetty:jetty-security:$jettyVersion"
implementation "org.eclipse.jetty:jetty-servlet:$jettyVersion"
implementation "org.eclipse.jetty:jetty-webapp:$jettyVersion"
implementation "org.eclipse.jetty:jetty-annotations:$jettyVersion"
implementation "org.eclipse.jetty:jetty-jmx:$jettyVersion"
}这是我的主修课:
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
MBeanContainer mbContainer = new MBeanContainer(getPlatformMBeanServer());
server.addBean(mbContainer);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar(warFile()); // LOGIC TO UPLOAD WAR FILE
webapp.setExtractWAR(true);
Configuration.ClassList classList = Configuration.ClassList.setServerDefault(server);
classList.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
"org.eclipse.jetty.annotations.AnnotationConfiguration");
webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$");
server.setHandler(webapp);
server.start();
server.dumpStdErr();
server.join();
}但是,当我尝试转到应用程序(http://localhost:8080/index)时,我一直收到以下错误消息:
URI: /index
STATUS: 500
MESSAGE: JSP support not configured
SERVLET: jsp控制台中只有一行错误消息:
2020-12-11 09:49:51.563:INFO:oejshC.ROOT:qtp2025864991-33: No JSP support. Check that JSP jars are in lib/jsp and that the JSP option has been specified to start.jar它指的是什么JSP Jars?对于我需要添加哪些依赖项才能使它在JSP上工作,我感到困惑。
谢谢。
发布于 2020-12-11 17:02:52
您必须添加apache,以便您的服务器能够支持jsps。如果您的web应用程序使用jstl,则还应该添加apache。
发布于 2020-12-11 17:17:03
对于WebAppContext使用(这比ServletContextHandler使用要容易一些),您将需要以下构件.
JettyJspServlet,它从Jasper JspServlet)扩展而来。
确保您的org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern能够正确引用apache工件,否则内部javax.servlet.ServletContextInitializer将无法正确加载。
如果仅仅添加这些工件就不会发生任何事情,则需要验证WebAppContext.setDefaultsDescriptor(String)上的默认描述符设置,以确保将资源引用(路径或uri)传递给Jetty默认描述符XML。
如果您使用ServletContextHandler而不是WebAppContext,在嵌入式模式下启用JSP支持可能会非常棘手。
如果您决定使用ServletContextHandler而不是WebAppContext (有一个fat/uber jar,以加快加载/部署时间,简化单元测试等等),那么请查看Jetty维护的示例项目。
https://stackoverflow.com/questions/65255476
复制相似问题