Search code examples
jettywar

Jetty Server not Working for War with JSPs


I am trying to create a simple jetty server/container that will take a war file and deploy. This is not embedded jetty with spring-boot.

Here is my build.gradle dependencies:

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"
}

Here is my main class:

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();
    }

However, when I try to go to the app (http://localhost:8080/index), I keep getting the following error message:

URI:    /index
STATUS: 500
MESSAGE:    JSP support not configured
SERVLET:    jsp

There is only one line of error message in the console:

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

What JSP Jars that it is referring to? I am at a loss as to what dependencies I need to add to make it work for JSPs.

Thx.


Solution

  • You will have to add apache-jsp so that your server will support jsps. If your web app uses jstl, you should also add apache-jstl.