java 检测到 JDK 版本:1.6.0-24 不在允许范围内 1.7

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15568835/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 20:06:11  来源:igfitidea点击:

Detected JDK Version: 1.6.0-24 is not in the allowed range 1.7

javamavencentos

提问by coure2011

When I ran the command

当我运行命令时

mvn clean package

I am getting error:

我收到错误:

Detected JDK Version: 1.6.0-24 is not in the allowed range 1.7.

How to fix the above error? I tried to check jdk version isntalled and got this

如何修复上述错误?我试图检查 jdk 版本没有安装并得到这个

java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

how to fix this?

如何解决这个问题?

回答by Charlee Chitsuk

Normally when execute the mvn -vyou may see something like

通常在执行时mvn -v你可能会看到类似的东西

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 
                    2013-02-19 20:51:28+0700)
Maven home: C:\Java.Application\Apache\apache-maven-3.0.5\bin\..
Java version: 1.7.0_15, vendor: Oracle Corporation
Java home: C:\Java.Application\Sun\Java\jdk1.7.0_15\jre
Default locale: en_US, platform encoding: MS874
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

If the result point to the JDK Version: 1.6.0-24or other than your expect. Please simply set the JAVA_HOMEto your JDK Version: 1.7.0_03instead.

如果结果指向JDK Version: 1.6.0-24或 超出您的预期。请简单地将 设置JAVA_HOME为您的JDK Version: 1.7.0_03

I hope this may help.

我希望这会有所帮助。

回答by nwinkler

Make sure that your environment (PATH) is set up to use the JDK version that you want to use for compiling. You can check this by running the following in the shell or command window where you want to run Maven:

确保您的环境 (PATH) 设置为使用要用于编译的 JDK 版本。您可以通过在要运行 Maven 的 shell 或命令窗口中运行以下命令来检查这一点:

java -version
javac -version

Make sure that both javaand javacare pointing to the correct version. It's possible that you have a 1.7 JRE (which does not include the compiler) and a 1.6 JDK (which includes the compiler) and the wrong one is being used.

确保javajavac都指向正确的版本。您可能有 1.7 JRE(不包括编译器)和 1.6 JDK(包括编译器)并且使用了错误的版本。

If necessary, adjust your JAVA_HOMEand PATHenvironment variables.

如果有必要,调整JAVA_HOMEPATH环境变量。

Just noticed that you're on CentOS - it's possible that javaand javacpoint to different versions. Use the alternativescommand to check that, see here for an example: http://wiki.centos.org/HowTos/JavaRuntimeEnvironment- you will have to check both the javaand the javaccommand.

刚刚注意到您使用的是 CentOS - 有可能java并且javac指向不同的版本。使用alternatives命令来检查,参见这里的例子:http: //wiki.centos.org/HowTos/JavaRuntimeEnvironment- 你必须同时检查javajavac命令。

回答by Edac

Check your JRE System Library in Eclipse. Does it show jdk1.6.0-24?

在 Eclipse 中检查您的 JRE 系统库。它是否显示 jdk1.6.0-24?

For me I had to right click the JRE System Library and go to Build Path -> Configure Build Path, in the Libraries tab I had to click JRE System Library and edit it. I set it to the Workspace Default JRE, which for me is jdk1.7.0_80 (not sure why it wasn't set to that already).

对我来说,我必须右键单击 JRE 系统库并转到构建路径 -> 配置构建路径,在库选项卡中,我必须单击 JRE 系统库并对其进行编辑。我将它设置为工作区默认 JRE,对我来说是 jdk1.7.0_80(不知道为什么还没有设置为)。