java 声纳扫描仪不受支持的major.minor 版本异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39677598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unsupported major.minor version Exception for sonar-scanner
提问by Amrish
I am trying to analyze my source code using SonarQube. I am trying to use sonar-scanner
as my tool to run analysis from command line. I followed the guidelines presented in this documentation article: http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
我正在尝试使用 SonarQube 分析我的源代码。我正在尝试将其sonar-scanner
用作从命令行运行分析的工具。我遵循了本文档文章中提供的指南:http: //docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
When I try to test the installation by running sonar-scanner -h
I am getting the following error:
当我尝试通过运行来测试安装sonar-scanner -h
时,出现以下错误:
? ~ sonar-scanner -h
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access0(URLClassLoader.java:71)
at java.net.URLClassLoader.run(URLClassLoader.java:361)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
From the error it looks like its not finding the right version for JAVA/JRE to run the cli tool. My understanding was that the tool should work with any Java 1.7+ version. I am using Oracle JDK 1.7.0_55
. I also tried using OpenJDK 1.8
but I am still getting the same error. I also checked my JAVA_HOME
variable is set to the right JDK directory.
从错误来看,它似乎没有为 JAVA/JRE 找到正确的版本来运行 cli 工具。我的理解是该工具应该适用于任何 Java 1.7+ 版本。我正在使用Oracle JDK 1.7.0_55
. 我也试过使用,OpenJDK 1.8
但我仍然遇到同样的错误。我还检查了我的JAVA_HOME
变量是否设置为正确的 JDK 目录。
Any help in the right direction is appreciated.
任何在正确方向上的帮助表示赞赏。
回答by Amrish
After Struggling with this for a while, I found the cause of the problem. The CLI is looking at your JAVA_HOME
path variable to figure out the version of Java it needs to use. even tough the default java
and javac
commands were pointing to JDK 8, setting the JAVA_HOME environment variable to your JDK 8 root directory solved the issue.
经过一段时间的挣扎,我找到了问题的原因。CLI 正在查看您的JAVA_HOME
路径变量以确定它需要使用的 Java 版本。即使默认java
和javac
命令指向 JDK 8,将 JAVA_HOME 环境变量设置为 JDK 8 根目录也解决了这个问题。
Hope this helps other folks facing similar issue.
希望这可以帮助其他面临类似问题的人。
回答by Alex
this have been already answered at length here : Unsupported major.minor version 52.0and here : How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
这已经在这里详细回答:不支持的major.minor版本52.0和这里:如何修复java.lang.UnsupportedClassVersionError:不支持的major.minor版本
the rationale is that you're trying to execute Sonar on a Java 7 or lower when the sonar classes have been compiled for java 8 thus triggering this error.
基本原理是当声纳类已为 java 8 编译时,您试图在 Java 7 或更低版本上执行声纳,从而触发此错误。