5

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.

Jevison7x
  • 709
  • 2
  • 14
  • 31
  • You lack a dependency: `jakarta.servlet.jsp.jstl-api`. To use JSTL in Tomcat 10 you actually need two (and only two) artifacts (cf. [this answer](https://stackoverflow.com/a/4928309/11748454)). – Piotr P. Karwasz Aug 08 '21 at 19:14
  • Reading your update, might I remark that the aforementioned [answer by BalusC](https://stackoverflow.com/a/4928309/11748454) doesn't deal only with the XML namespace. It gives you the exact dependencies you must use in various Tomcat versions and their download links. It's a long answer, but worth reading. – Piotr P. Karwasz Aug 08 '21 at 19:56
  • Sorry, my bad, it appears I stopped at the part where he talked about the URI problem. However I have solved it in my own way. I will go back and test his solution for Tomcat 10 later. – Jevison7x Aug 08 '21 at 20:16
  • also check out this answer which worked for me https://stackoverflow.com/questions/75123103/java-lang-noclassdeffounderror-jakarta-servlet-jsp-jstl-core-config-in-tomcat – Magnus Aug 04 '23 at 21:50

3 Answers3

7

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

Jevison7x
  • 709
  • 2
  • 14
  • 31
4

I managed to find a solution which is to add both these maven dependencies (The Tomcat version I use is 10.1.7):

<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>jakarta.servlet.jsp.jstl</artifactId>
    <version>3.0.1</version>
</dependency>
<dependency>
    <groupId>jakarta.servlet.jsp.jstl</groupId>
    <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
    <version>3.0.0</version>
</dependency>

Previously, I only tried adding only one of them, only to find out that I had to add both.

-3

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

chu3la
  • 18
  • 5
  • This is what I had before. This doesn't work for Tomcat 10, it throws an error. From the image you are showing me, you are using Tomcat 8. – Jevison7x Aug 07 '21 at 18:48
  • it does not depend on the tomcat version, moreover, Tomcat has never included JSTL add both jars in WEB-INF/lib, I've checked the image that you've put above, I did not realize where is jstl-api jar file, please check the permission to read them – chu3la Aug 07 '21 at 18:57
  • @chu3la: JSTL 1.2 does not work with JSP 3.0 (in Tomcat 10), due to the `javax.*` -> `jakarta.*` namespace migration. Therefore the version of JSTL that you need to install **does** depend on the version of Tomcat. – Piotr P. Karwasz Aug 08 '21 at 19:18
  • I've used the instruction that I've given you above and works perfectly, in addition, I checked my JSP version I found 4.0 when I've consulted Project Facets – chu3la Aug 09 '21 at 14:43