javajspjstljsp-tagstomcat10

java.lang.NoClassDefFoundError: jakarta/servlet/jsp/jstl/core/LoopTag in Tomcat 10


I just migrated to Tomcat 10. After changing all references of javax.servlet packages to jakarta.servlet I still can't get my app to run.

I have downloaded the JSTL 2.0 class libraries from Here and I added them to the classpath. I am using NetBeans with Ant. Here are my class libraries:

Class Libraries

And here is the JSTL jar files I added:

JSTL Jar files

It throws the following Exception:

Type Exception Report

Message java.lang.NoClassDefFoundError: jakarta/servlet/jsp/jstl/core/LoopTag

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

jakarta.servlet.ServletException: java.lang.NoClassDefFoundError: jakarta/servlet/jsp/jstl/core/LoopTag
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)
    jakarta.servlet.http.HttpServlet.service(HttpServlet.java:770)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    com.xyneex.post.PostFilter.doFilter(PostFilter.java:163)

Root Cause

java.lang.NoClassDefFoundError: jakarta/servlet/jsp/jstl/core/LoopTag
java.base/java.lang.ClassLoader.defineClass1(Native Method)
java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2470)
org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:866)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1370)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1232)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1464)
org.apache.jasper.compiler.Parser.parse(Parser.java:138)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:244)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:105)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:207)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:392)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:368)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:400)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:327)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:770)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
com.xyneex.post.PostFilter.doFilter(PostFilter.java:163)

Root Cause

java.lang.ClassNotFoundException: jakarta.servlet.jsp.jstl.core.LoopTag
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1401)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
java.base/java.lang.ClassLoader.defineClass1(Native Method)
java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2470)
org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:866)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1370)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1232)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1464)
org.apache.jasper.compiler.Parser.parse(Parser.java:138)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:244)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:105)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:207)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:392)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:368)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:400)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:327)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:770)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
com.xyneex.post.PostFilter.doFilter(PostFilter.java:163)

Note The full stack trace of the root cause is available in the server logs.

My JSP/HTML code:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="home" value="active" scope="request" />
<!DOCTYPE html>
<html>
    <head>
        <title>Xyneex Technologies | Home </title>
        <jsp:include page="WEB-INF/fragments/head.jsp" />
        <style>
     ...

I have seen similar questions here in StackOverflow but they are talking about Tomcat 7.

I am using Tomcat 10 with JDK 16.

Please what is the solution to this problem?

EDIT:

Based on suggestion, This Question and Answer is not the same problem as mine. As the answer addresses JSTL URI and I have checked and confirmed that I am using the correct URI. I strongly believe the problem has to do with incorrect JSTL jar files in my JSTL library which I cannot determine which ones to use.

EDIT 2:

After digging around for hours I was able to find a solution which I have provided in my answer. Thanks for your suggestions.

EDIT 3:

This Answer by BalusC seems to address the problem with Tomcat 10. Please make sure when reading the answer, you scroll down to the Tomcat 10 part. I must have missed it the first time because I thought he only talked about the URI.

Thanks to Piotr P. Karwasz for pointing it out for me.


Solution

  • I found a solution at last!

    I was able to download the required jar files here

    For those who may be having the same problems: Please Note: When adding the jar files, don't include the jakarta.servlet-api-5.0.0.jar file. Tomcat 10 already has a similar jar file with the same classes and this caused another headache. I created a new Library and named it JSTL 2.0

    Below is a screenshot of the jar files I added to the classpath.

    This works fine for me!

    JSTL Solution