Home > Back-end >  java.lang.NoClassDefFoundError: jakarta/servlet/jsp/jstl/core/LoopTag in Tomcat 10
java.lang.NoClassDefFoundError: jakarta/servlet/jsp/jstl/core/LoopTag in Tomcat 10

Time:09-17

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 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, JSTL Solution

CodePudding user response:

You could add JSTL1.2 Library to your application as shown below, jstl-impl.jar and jstl-api.jar added to the application

enter image description here

the taglib directive that specifies the JSTL core library:

<%taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

the link to download the files

http://www.java2s.com/Code/Jar/j/Downloadjstlapi12jar.htm http://www.java2s.com/Code/Jar/j/Downloadjstlimpl12jar.htm

don't forget to add both jar files to META-INF/lib, it will work fine without all those files that you've put in your application

  • Related