在运行脚本时,我在Eclipse控制台中得到以下错误消息:
类已经由最新版本的Java环境(类文件版本53.0)编译,该版本的Java运行时只识别52.0以下的类文件版本。
Java版本:8 IDE: Eclipse Oxygen Firefox版本:46
在运行脚本时,我在Eclipse控制台中得到以下错误消息:
类已经由最新版本的Java环境(类文件版本53.0)编译,该版本的Java运行时只识别52.0以下的类文件版本。
Java版本:8 IDE: Eclipse Oxygen Firefox版本:46
当前回答
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")
其他回答
通过导航到“设置->构建,执行,部署>构建工具> Gradle”来检查IDE中配置的Java版本
我写这篇文章是因为我发现其他答案很难理解。
基本上,您的JRE没有更新,并且/或Eclipse没有配置为使用最新的JRE。
在Windows操作系统下,进入“控制面板->程序-> Java ->更新”,继续更新Java
或者如果你没有Java,去甲骨文的网站下载最新的JRE。
完成后,进入eclipse,在项目视图下,右键单击项目,选择Java Build Path,双击JRE System Library,然后选择Workspace Default JRE 14.1。
如果这里没有显示最新版本的Java,则可能没有安装。检查您的JRE(不是JDK)版本,并确保它是最新的。如果是,请重新启动计算机,然后再试一次。
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")
如果您正在使用IntelliJ IDEA并遇到此错误,请尝试此操作。
1. Command + , (Open Preferences)
2. Build, Execution, Deployment > Build Tools > Gradle
3. Gradle JVM > Change it to a proper version
我在Windows 10上复制了类似的问题,格式如下:
Error: LinkageError occurred while loading main class ...
java.lang.UnsupportedClassVersionError: com/.../ServiceApplication
has been compiled by a more recent version of the Java Runtime (class file version 62.0),
this version of the Java Runtime only recognizes class file versions up to 61.0
将项目从Java 17升级到Java 18。
我有关于Java 18的项目设置:
命令行:
Java版本“18.0.1.1”2022-04-22 Java(TM) SE运行时环境(build 18.0.1.1+2-6) Java HotSpot(TM) 64位服务器虚拟机(build 18.0.1.1+2-6,混合模式,共享)
项目结构->项目设置->项目:
项目结构->项目设置->模块:
项目结构->平台设置-> sdk:
这个问题的原因是:
我忘记为运行/调试配置指定正确的版本->构建并运行到Java 18而不是Java 17:
因为它是用较新的Java版本编译的,但运行在较旧的版本上。
如果是与maven相关的问题,您可以通过指定Java编译器的-source和-target来修改POM。
其他有用的链接:
在Maven中设置Java版本 使用特定Java版本的Jar工件