javac:无效的目标版本:1.8
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24766591/
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
javac: invalid target release: 1.8
提问by Program-Me-Rev
I recently downloaded JDK 1.8.0.0_06 that comes bundled with NetBeans. I then got to find out that my JavaFx project, that I have been developing in Java 1.7 won't compile in Java 1.8, and so I stepped down my JDK to 1.7. Still I can't get it to work/ compile. I get this error:
我最近下载了与 NetBeans 捆绑在一起的 JDK 1.8.0.0_06。然后我发现我在 Java 1.7 中开发的 JavaFx 项目不能在 Java 1.8 中编译,所以我将我的 JDK 降级到 1.7。我仍然无法让它工作/编译。我收到此错误:
javac: invalid target release: 1.8
Usage: javac <options> <source files>
I'm really stuck and would greatly appreciate any help.
我真的被困住了,非常感谢任何帮助。
采纳答案by Jigar Joshi
if you are going to step down, then change your project's source to 1.7 as well,
如果你打算下台,那么把你的项目的源代码也改成 1.7,
right click on your Project -> Properties -> Sources window
and set 1.7
here
并设置1.7
在这里
note: however I would suggest you to figure out why it doesn't work on 1.8
注意:但是我建议您弄清楚为什么它在 1.8 上不起作用
回答by Piyush Jajoo
Your javac is not pointing to correct java.
您的 javac 没有指向正确的 java。
Check where your javac is pointing using following command -
使用以下命令检查您的 javac 指向的位置 -
update-alternatives --config javac
If it is not pointed to the javac you want to compile with, point it to "/JAVA8_HOME/bin/javac", or which ever java you want to compile with.
如果它没有指向您要编译的 javac,请将其指向“/JAVA8_HOME/bin/javac”,或者您要编译的 javac。
回答by thorinkor
- Download JDK 8.
Edit your env var for
JAVA_HOME
to point to the new installed JDK 1.8: R-click on My Computer -> Properties -> Advanced System Settings -> Environment Variables findJAVA_HOME
on the list and set it's value to something like that:C:\Program Files\Java\jdk1.8.0_31
Find the old version and edit it in
PATH
variable aswell.- Probably you will need to restart the system.
- 下载JDK 8。
编辑您的 env var
JAVA_HOME
以指向新安装的 JDK 1.8:R 单击我的电脑 -> 属性 -> 高级系统设置 -> 环境变量JAVA_HOME
在列表中找到并将其值设置为类似的值:C:\Program Files\Java\jdk1.8.0_31
找到旧版本并在
PATH
变量中编辑它。- 您可能需要重新启动系统。
Should be done.
需要被完成。
回答by vikasing
For IntelliJ14 you may have to change the bytecode version w.r.t. the JDK you are using (in the global settings):
对于 IntelliJ14,您可能需要更改正在使用的 JDK 的字节码版本(在全局设置中):
回答by it-webwork
Maven setting:
Maven 设置:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
回答by juliangonzalez
If this error occurs when running a Gradle (or Maven) task, you need to modify that build tool configuration to point to your installation of Java JDK 1.8 following this route:
如果在运行 Gradle(或 Maven)任务时发生此错误,您需要修改该构建工具配置以指向您按照以下路线安装的 Java JDK 1.8:
File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
文件 -> 设置 -> 构建、执行、部署 -> 构建工具 -> Gradle
There you check the Linked Gradle project is the one you are working on and select the Gradle JVM (You missed this when you imported the gradle project into IntelliJ)
在那里你检查 Linked Gradle 项目是你正在处理的项目并选择 Gradle JVM(当你将 gradle 项目导入 IntelliJ 时你错过了这个)
Remember when importing a Gradle (or Maven) project to set the target JVM correctly here:
回答by JAG NUNEZ
if you are going to step down, then change your project's source to 1.7 as well,
right click on your Project -> Properties -> Sources window and set 1.7 here" Jigar Joshi
如果你打算下台,那么把你的项目的源代码也改成 1.7,
右键单击您的项目 -> 属性 -> 源窗口并在此处设置 1.7” Jigar Joshi
Also go to the build-impl.xml
and look for the property excludeFromCopy="${copylibs.excludes}"
and delete this property on my code was at line 827 but I`ve seen it on other lines
也去build-impl.xml
寻找属性excludeFromCopy="${copylibs.excludes}"
并在我的代码中删除这个属性是在第 827 行,但我已经在其他行看到了
for me was taking a code from MAC OS java 1.8 to WIN XP java 1.7
对我来说是从 MAC OS java 1.8 到 WIN XP java 1.7 的代码
回答by nanospeck
Alternatively, I checked the pom.xml and changed
或者,我检查了 pom.xml 并更改了
<java.version>1.8</java.version>
to
到
<java.version>1.7</java.version>
回答by jprism
Most of the time, these type of issues happen due to incorrect java version. Make sure your PATH and JAVA_HOME variables are pointing to the correct version.
大多数情况下,这些类型的问题是由于 Java 版本不正确造成的。确保您的 PATH 和 JAVA_HOME 变量指向正确的版本。
回答by Bill Masek
None of the previous solutions worked for me.
以前的解决方案都不适合我。
I solved it by editing .idea/compiler.xml There were "extra" (1) and (2) copies of the bad module with different targets. I deleted the extraneous entried and changed the targets in the section to 1.8 and it worked.
我通过编辑 .idea/compiler.xml 解决了它有不同目标的坏模块的“额外”(1)和(2)副本。我删除了无关的条目并将该部分中的目标更改为 1.8 并且它起作用了。