Home » Java » java.lang.UnsupportedClassVersionError in Dynamic Web Project (Eclipse)-Exceptionshub

java.lang.UnsupportedClassVersionError in Dynamic Web Project (Eclipse)-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am looking to create a basic web app using eclipse and Azure. I am able to get basic print statements uploaded to the internet but when i try to reference a class in the same project, but different package, i get an error screen. I dont understand these errors and have made sure that i updated and reinstalled a new version of JDK. This only happens when calling another class. The original error was “tester/Lowercase has been compiled by a more recent version of Java Runtime (class file version 57), this version of the Runtime only recognizes class file versions up to 52.0 (unable to load class [tester.Lowercase()]”. That is when i installed a different JDK, and now i am getting a different error that im having a harder time finding the solution for. The error shown in index.jsp is “The superclass “javax.servlet.http.HttpServlet” was not found on the java build path”. I chose to ignore this for now, since a friend did the same exact code as me on his computer and was able to get it to work easily. This error was also resolved when i selected Tomcat under runtimes in my Project Facets, in the properties menu of my project.

This is the jsp file titled “index.jsp”

<%@ page import="tester.Lowercase" %>
<html>
<body>
   <% out.println(Lowercase.makeItLower("MAKE THIS LOWERCASE")); %>
</body>
</html>

This is the java class titled “Lowercase.java”

package tester;

public class Lowercase {
   public static String makeItLower(String data) {
      String str = data.toLowerCase();
      return str;
   }
}

I know this is really simple code and should be a simple task, but this error i am getting is stopping me from advancing in making this webapp.

How to&Answers:

You say that you have solved the UnsupportedClassVersionError problem, so I won’t talk about that.

Java SE does not include javax.servlet.http.HttpServlet in its class library. That class and related classes comes from the Java EE APIs. So to compile your JSP in Eclipse you need to configure the build path for your project to include a JAR file containing those APIs.

You can download different versions of the APIs from Maven Central; for example, this page will give you the 3.0.1 version https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/3.0.1. Click on the “jar” link on that page. Or if you are using one of the supported build tools, add the corresponding dependency information on that page to your build file.

The reason your JSP works when you deploy it to Tomcat is that Tomcat has its own copy of the servlet classes, and it automatically includes them on its build classpath when it compiles a JSP.