Home > Software design >  Jetty - upgrading 9.3.0.M1 to 9.3.0.M2 breaks JSP functionality using Maven
Jetty - upgrading 9.3.0.M1 to 9.3.0.M2 breaks JSP functionality using Maven

Time:08-29

Related: Jasper exception PWC6188 - Jetty cannot resolve javax.servlet.jstl.fmt TLD to JSTL classes inside project

Related: Jetty 9 migrate from JDK1.8 to JDK11 - http://java.sun.com/jsp/jstl/fmt cannot be resolved in JDK11 - fat exec jar

I want to upgrade my Jetty instance as indicated above.

I am at the 9.2.2.v20140723 Jetty Maven artifact currently, and I'm working upward through the versions to get my Jetty instance current.

Beyond Maven Jetty artifact 9.3.0.M1 (e. g. going to 9.3.0.M2 in my pom.xml), all JSP functionality stops working.

These Maven artifacts give me full JSP functionality using Jetty 9.3.0.M1 - Netbeans 11, JDK 1.8:

pom.xml:

.
.
.
<dependency>
 <groupId>org.eclipse.jetty.websocket</groupId>
 <artifactId>websocket-client</artifactId>
 <version>9.3.0.M1</version>
</dependency> 

<dependency>
 <groupId>org.eclipse.jetty</groupId>
 <artifactId>jetty-server</artifactId>
 <version>9.3.0.M1</version>
</dependency>

<dependency>
 <groupId>org.eclipse.jetty</groupId>
 <artifactId>jetty-servlet</artifactId>
 <version>9.3.0.M1</version>
</dependency>

<dependency>
 <groupId>org.eclipse.jetty</groupId>
 <artifactId>jetty-webapp</artifactId>
 <version>9.3.0.M1</version>
</dependency>

<dependency>
 <groupId>org.eclipse.jetty</groupId>
 <artifactId>jetty-jsp</artifactId>
 <version>9.3.0.M1</version>
</dependency>
.
.
.

HOWEVER

Going to 9.3.0.M2 results in a compile-time failure e.g.

Failed to execute goal on project verdi: Could not resolve dependencies for project verishare:verdi:jar:1.0-SNAPSHOT: Could not find artifact org.eclipse.jetty:jetty-jsp:jar:9.3.0.M2 in central (https://repo.maven.apache.org/maven2) -> [Help 1]

e. g. it appears the artifact

org.eclipse.jetty:jetty-jsp:jar:9.3.0.M1

has been deprecated in the Central maven repo for Jetty version 9.3.0.M2 and upward.

What replaced org.eclipse.jetty:jetty-jsp:jar:9.3.0.M1?

Note that I have tried removing the pom.xml reference to jetty-jsp in my project and replacing with

pom.xml:

<dependency>
 <groupId>org.eclipse.jetty</groupId>
 <artifactId>apache-jsp</artifactId>
 <version>9.3.0.M2</version>
</dependency>         

<dependency>
 <groupId>jstl</groupId>
 <artifactId>jstl</artifactId>
 <version>1.2</version>
</dependency>

at which point the code compiles, but trying to render any .jsp pages gives an exception.

I have added to my WebAppContext as posts suggest

WebAppContext waContext = new WebAppContext(webDir, "/");
            waContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
            waContext.setSecurityHandler(basicSecurity);
              waContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",".*/[^/]*jstl.*\\.jar$");

but the error remains the same if the 9.3.0.M2 version without the Jetty-JSP Maven artifact is run. The exception for 9.3.0.M2 with the JSTL and Apache-JSP artifacts is

HTTP ERROR 500

Problem accessing /index.jsp. Reason:

    Server Error

Caused by:

org.apache.jasper.JasperException: Unable to compile class for JSP
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:579)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:405)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:349)
    at org.eclipse.jetty.jsp.JettyJspServlet.service(JettyJspServlet.java:107)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:806)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:526)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1128)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1062)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
    at org.eclipse.jetty.server.Server.handle(Server.java:507)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:284)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:237)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:240)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:93)
    at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:53)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceRun.produceAndRun(ExecuteProduceRun.java:191)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceRun.run(ExecuteProduceRun.java:126)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:641)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:559)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at org.apache.jasper.JspCompilationContext.getTldResourcePath(JspCompilationContext.java:530)
    at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:410)
    at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:469)
    at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1428)
    at org.apache.jasper.compiler.Parser.parse(Parser.java:139)
    at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:227)
    at org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
    ... 28 more

Caused by:

java.lang.NullPointerException
    at org.apache.jasper.JspCompilationContext.getTldResourcePath(JspCompilationContext.java:530)
    at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:410)
    at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:469)
    at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1428)
    at org.apache.jasper.compiler.Parser.parse(Parser.java:139)
    at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:227)
    at org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:405)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:349)
    at org.eclipse.jetty.jsp.JettyJspServlet.service(JettyJspServlet.java:107)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:806)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:526)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1128)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1062)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
    at org.eclipse.jetty.server.Server.handle(Server.java:507)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:284)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:237)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:240)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:93)
    at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:53)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceRun.produceAndRun(ExecuteProduceRun.java:191)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceRun.run(ExecuteProduceRun.java:126)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:641)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:559)
    at java.lang.Thread.run(Thread.java:745)

How can I upgrade Jetty beyond 9.3.0.M1 and retain JSP functionality?

Thanks!

CodePudding user response:

This was resolved by firstly upgrading the JDK being used from 1.8 to the current LTS JDK 17 version.

Then, the non-Apache jetty-jsp artifact was removed, e. g. in pom.xml

<!--
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-jsp</artifactId>
            <version>${jettyVersion}</version>
        </dependency>        
-->

then add to the pom.xml

        <dependency> 
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-webapp</artifactId>
            <version>${jettyVersion}</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-annotations</artifactId>
            <version>${jettyVersion}</version>
        </dependency>
        
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>apache-jsp</artifactId>
            <version>${jettyVersion}</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>apache-jstl</artifactId>
            <version>${jettyVersion}</version>        
        </dependency>

with jettyVersion becoming at least

<jettyVersion>9.4.48.v20220622</jettyVersion>

in the pom.xml.

I also upgraded my Netbeans from NetBeans 11 to NetBeans 14, not sure if that also had a positive effect to get this working. Only tested so far inside NetBeans itself, haven't tried deploying the .jar yet to the operational server involved.

Still experimenting if higher Jetty versions nearer to current (as of 2022-08-26) still work, but doing the above solved my issue with "native" Jetty JSP being deprecated in Jetty version 9.3.0.M2.

Once this was done, JSP functionality was present in the newer, higher Jetty versions beyond 9.3.0.M1.

Hope this helps someone.

EDIT: I forgot I also had to do this to my WebappContext whens starting jetty to make PWC6188 exception above go away when starting Jetty:

.
.
.
            WebAppContext waContext = new WebAppContext(webDir, "/");            
              waContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
            waContext.setSecurityHandler(basicSecurity);  
            
            waContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$");

            server.setHandler(waContext);
.
.
.

e.g. I had to add

waContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$");

or else in Jetty 9.3.0.M2 I again had the same exception.

  • Related