Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalArgumentException: Unsupported class file major version 59

Tags:

I am working on my first project with Java restful webservices, but I am running into some issues. When I run the server with Tomcat and type the url of the GET service, I get a HTTP Status 500 – Internal Server Error. I did research for hours but cannot find anything. Maybe there is some issue in the pom.xml.

Below some code:

ResourceConfig:

package nl.hu.bep.IPASS.Config;

import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;

@ApplicationPath("/restservices")
public class JerseyConfig extends ResourceConfig {

    public JerseyConfig(){
        packages("nl.hu.bep.IPASS.webservices");


    }
}

Resource code:

import nl.hu.bep.IPASS.model.Product;
import nl.hu.bep.IPASS.model.ProductBeheer;


import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

@Path("/producten")
public class ProductResource {
    @GET
    @Produces("application/json")
    public Response getProducten(){
        ProductBeheer beheer = ProductBeheer.getInstance();

        return Response.ok(beheer.getAlleProducten()).build();

    }

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>nl.hu.bep.IPASS</groupId>
  <artifactId>SD_IPASS_2021</artifactId>
  <version>1.0</version>
  <packaging>war</packaging>

  <name>SD_IPASS_2021</name>


  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>15</maven.compiler.source>
    <maven.compiler.target>15</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.glassfish</groupId>
      <artifactId>javax.json</artifactId>
      <version>1.0.4</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.inject</groupId>
      <artifactId>jersey-hk2</artifactId>
      <version>2.30.1</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.containers</groupId>
      <artifactId>jersey-container-servlet</artifactId>
      <version>2.30.1</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-json-jackson</artifactId>
      <version>2.30.1</version>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>42.2.20</version>
    </dependency>
    <dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt</artifactId>
      <version>0.9.1</version>
    </dependency>


    <dependency>
      <groupId>com.azure</groupId>
      <artifactId>azure-storage-blob</artifactId>
      <version>12.6.0</version>
    </dependency>




    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>5.6.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.1</version>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->

        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>


      </plugins>
    </pluginManagement>
  </build>
</project>

error:

Screenshot Error

Can someone help me please?

like image 463
programmer_66 Avatar asked Jun 24 '21 00:06

programmer_66


2 Answers

You've made class files that cannot be read by JDK14 and downwards; you need at least JDK15. That's what '59' means (it's the class file format version emitted by JDK15).

You have two options:

Downgrade

<maven.compiler.source>15</maven.compiler.source> - make this a lower version, at least as low as the version of the JDK you installed on your server.

Upgrade

Upgrade your server to run JDK15 or up. Specifically, when you run your tomcat, somewhere, somehow, the java executable is run. That needs to be JDK15 (you can install multiple JDKs on one system - that's fine, but the one used to run tomcat needs to be 15 or up).

like image 172
rzwitserloot Avatar answered Sep 30 '22 17:09

rzwitserloot


I also got same erorr while building android release apk for my flutter project , I resolved this by adding :

android.jetifier.blacklist=bcprov-jdk15on

in gradle.properties file and rebuild the project and it worked for me.

If this work for you that's good else you can refer to this issue on github here and this.

like image 28
MANISH Avatar answered Sep 30 '22 17:09

MANISH