在运行脚本时,我在Eclipse控制台中得到以下错误消息:

类已经由最新版本的Java环境(类文件版本53.0)编译,该版本的Java运行时只识别52.0以下的类文件版本。


Java版本:8 IDE: Eclipse Oxygen Firefox版本:46


当前回答

在我的情况下,我用VS2019构建一些使用ANTLR4的c++代码。 ANTLR4是基于java的,为了使用它,我运行java命令作为自定义构建步骤。

那天早些时候,我把我的新笔记本电脑上的JRE (Java运行时环境)更新到了1.8。没有思考,因为我已经有一年没有运行ANTLR4的东西了……我需要完整的JDK编译与java。所以我有一个1.8的RUNTIME,但VS2019构建shell正在寻找JDK1.7编译器。一旦我安装了1.8 JDK,一切都很好。

所以80%的时间JRE对我来说是好的…只是当我需要完整的JDK时,DOH我需要完整的JDK。

其他回答

对我来说,解决方案是按照安德烈·库兹涅佐夫在https://youtrack.jetbrains.com/issue/IDEA-251407/Failed-to-run-Android-project-in-the-Idea-20203-EAP-OutputBuildAction-has-been-compiled-by-a-more-recent-version-of-the-Java上所说的去做,总结如下:

根本原因:IDEA源码现在是基于Java 11编译的。已知的解决方法是将Java 11配置为Gradle JVM。”(Andrei“库兹涅佐夫”)

对于临时解决方案,只需右键单击项目=>属性=> Java编译器=>在那里请选择编译器兼容级别1.8 => .class兼容性1.8 =>源代码兼容性1.8。

然后您的代码将开始在版本1.8上执行。

你可能在IntelliJ中也会看到这个错误,在谷歌中也会出现。

我认为这是一个Gradle错误而不是IDE错误。

修复(从这里偷来的)是在IntelliJ中将Java 11配置为Gradle JVM:

文件->设置->构建,执行和开发->构建工具-> Gradle并将Gradle JVM更改为11

这张截图也是从《Jetbrains》中偷来的

在build.gradle(app)中更新如下:(为我工作)

 kotlinOptions {
        jvmTarget = '1.8'
    }

Sonarqube也有同样的问题

已经由最新版本的Java运行时(类文件版本55.0)编译,这个版本的Java运行时只识别类文件版本52.0

Sonarqube与AzureDevOps错误输出:

INFO: SonarScanner 4.6.2.2472 INFO: Java 1.8.0_231 Oracle Corporation (32-bit) INFO: Windows Server 2016 10.0 x86 INFO: User cache: C:\Windows\system32\config\systemprofile.sonar\cache INFO: Scanner configuration file: C:\agent_a_work_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\5.4.0\classic-sonar-scanner-msbuild\sonar-scanner-4.6.2.2472\bin..\conf\sonar-scanner.properties INFO: Project root configuration file: C:\agent_a_work\189.sonarqube\out\sonar-project.properties INFO: Analyzing on SonarQube server 9.4.0 INFO: Default locale: "en_AU", source code encoding: "windows-1252" (analysis is platform dependent) INFO: ------------------------------------------------------------------------ INFO: EXECUTION FAILURE INFO: ------------------------------------------------------------------------ INFO: Total time: 0.405s INFO: Final Memory: 3M/15M ##[error]ERROR: Error during SonarScanner execution java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0


我在Sonarcube服务器上安装了Java v11,但错误提示它的构建代理没有Java v11。

我决定将Java v12 bin路径添加到环境变量路径中,以便检测它。重要的是,这需要在构建代理上完成:

对于托管生成代理,您可以安装JDK v11或使用以下PowerShell脚本步骤:

- task: PowerShell@2
  displayName: 'Download and Install Java v11'
  inputs:
    targetType: 'inline'
    script: |
      [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
      $Command = "c:\jdk-11.0.15_windows-x64_bin.exe"
      $Parms = "/s"
      Write-Host [System.IO.File]::Exists($Command)
      if ([System.IO.File]::Exists($Command)) {
        Write-Host 'Downloading Java11.exe'      
        Invoke-WebRequest https://yourOwnUrl.com/jdk-11.0.15_windows-x64_bin.exe -OutFile $Command
      }
      Write-Host [System.IO.File]::Exists($Command)
      & "$Command" $Prms
      [System.Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Java\jdk-11.0.15")
      [System.Environment]::SetEnvironmentVariable("Path", [System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine) + ";$($env:JAVA_HOME)\bin")