13

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

Below is 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?

MANISH
  • 2,883
  • 4
  • 11
  • 30
programmer_66
  • 131
  • 1
  • 1
  • 3
  • 2
    Q: "I did research for hours but cannot find anything". All you have to do is Google on the error message: `java.lang.IllegalArgumentException: Unsupported class file major version 59`. The JVM you're running doesn't support the class file(s) you're trying to load. Specifically, "59" is Java 15: https://javaalmanac.io/bytecode/versions/. So either 1) find an older .jar, or 2) run a newer JVM. – paulsm4 Jun 24 '21 at 00:43
  • 1
    when I Googled the error message, this was the first result – Adam Burley Nov 18 '21 at 09:41

3 Answers3

18

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.

MANISH
  • 2,883
  • 4
  • 11
  • 30
7

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).

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
  • 3
    And remember that Oracle hates developers - Java 12 through Java 15 are already past support. Java 11 is a "long term support" release. If your code is meant to be production you should look at using Java 11 for now until Java 17 comes out in September of 2021. – stdunbar Jun 24 '21 at 00:51
  • 1
    Thanks for the reply. I have looked on whick JDK version tomcat runs in my project and it seems like its running on JDK15. However I discovered that when I refresh the error page couple times it works. Very strange. – programmer_66 Jun 24 '21 at 01:16
  • @programmer_66 'a couple of times' makes no sense. 'one time' - that suggests that you used to run it on a too-low version but no longer do so, and that the cache config is messed up. (and note that 'there is no cache config counts, as that means caching occurs) - as in, your browser is showing the cached version, and thus reloading 'fixes it'. You need to look into cache directives to fix this. – rzwitserloot Jun 24 '21 at 13:24
1

How I fixed this issue, using a mac, clicking on Android Studio on the top left corner of your screen, then click on Preferences

enter image description here

Click on Build, Execution, Deployment, click on Build Tools and select Gradle. Where you see Gradle JDK, click the drop-down and select any Embedded JDK lower than 15, in this example, I used 11.0.13.

enter image description here

Then click on Apply, and Ok.

You should be good now.