java.lang.IllegalArgumentException:不支持的类文件主要版本 59 [英] java.lang.IllegalArgumentException: Unsupported class file major version 59

查看:44
本文介绍了java.lang.IllegalArgumentException:不支持的类文件主要版本 59的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Java RESTful Web 服务开展我的第一个项目,但遇到了一些问题.当我使用 Tomcat 运行服务器并输入 GET 服务的 URL 时,我收到 HTTP 状态 500 – 内部服务器错误.我做了几个小时的研究,但找不到任何东西.可能 pom.xml 有问题.

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.

下面是一些代码:

资源配置:

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");


    }
}

资源代码:

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>

错误:

截图错误

有人可以帮我吗?

推荐答案

您制作了 JDK14 及以下版本无法读取的类文件;你至少需要JDK15.这就是'59'的意思(它是JDK15发出的类文件格式版本).

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

您有两个选择:

<maven.compiler.source>15</maven.compiler.source> - 将其设为较低版本,至少与您在服务器上安装的 JDK 版本一样低.

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

升级您的服务器以运行 JDK15 或更高版本.具体来说,当您运行 tomcat 时,以某种方式在某处运行 java 可执行文件.那需要是 JDK15(你可以在一个系统上安装多个 JDK - 这很好,但是用于运行 tomcat 的需要 15 或更高版本).

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

这篇关于java.lang.IllegalArgumentException:不支持的类文件主要版本 59的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆