简体   繁体   English

IntelliJ IDEA 2016.3无法使用Java 7进行编译

[英]IntelliJ IDEA 2016.3 unable to compile with java 7

  • I've recently updated to IntelliJ IDEA 2016.3 and I just noticed that whenever I have a project with a java 7 SDK selected, IntelliJ compiles the project with java 1.8.0_112-release (which must be a compiler bundled with IntelliJ because I have never installed it myself). 我最近更新到了IntelliJ IDEA 2016.3,我刚刚注意到,只要我有一个选择了Java 7 SDK的项目,IntelliJ就会使用Java 1.8.0_112-release(必须是与IntelliJ捆绑在一起的编译器)编译该项目。自己安装)。

  • If I select a java 8 SDK other than the 1.8.0_112-release, IntelliJ compiles with that compiler. 如果选择1.8.0_112发行版以外的Java 8 SDK,则IntelliJ会使用该编译器进行编译。

  • If I have a java 7 SDK selected and run a main method in my project, IntelliJ uses that java 7 SDK version to run so the issues seems to only relate to the compiler. 如果我选择了Java 7 SDK并在项目中运行main方法,则IntelliJ使用该Java 7 SDK版本运行,因此问题似乎仅与编译器有关。

  • I have tried re-installing all my java installations. 我尝试重新安装所有Java安装。

  • When I change the SDK I usually only change Project Structure -> Project -> Project SDK , but I also verify that the Language level is correct and that Project Structure -> Modules -> Dependencies -> Module SDK is correct. 当我更改SDK时,通常只更改Project Structure -> Project -> Project SDK ,但我还要验证语言级别是否正确以及Project Structure -> Modules -> Dependencies -> Module SDK是否正确。

  • All settings are default under: 所有设置均为以下默认设置:

    • Settings -> Build, Execution, Deployment -> Compiler/Java Compiler
  • It seems to me that IntelliJ IDEA 2016.3 is not able to use a java compiler lower than java 8, but my googling attempts have not been able to confirm this. 在我看来,IntelliJ IDEA 2016.3无法使用低于Java 8的Java编译器,但我的谷歌搜索尝试无法确认这一点。

  • I can also mention that the only thing I haven't tried yet is a hard uninstall of IntelliJ where all my settings are wiped as well. 我还可以提到,我还没有尝试过的唯一事情是硬卸载IntelliJ,在那里我所有的设置也都被清除了。 A silent uninstall have been tried. 已尝试进行无提示卸载。

  • If I try to compile a new Hello World project with a Java 7 SDK this is the output in the Messages tab: Information:Using javac 1.8.0_112-release to compile java sources . 如果我尝试使用Java 7 SDK编译新的Hello World项目,则这是“消息”选项卡中的输出: Information:Using javac 1.8.0_112-release to compile java sources If however I set the project SDK to a Java 8 SDK this is the output in the Messages tab: Information:Using javac 1.8.0_45 to compile java sources . 但是,如果我将项目SDK设置为Java 8 SDK,则这是“消息”选项卡中的输出: Information:Using javac 1.8.0_45 to compile java sources

  • Have tried setting Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler -> Project bytecode version to 1.7 without any effect. 尝试将Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler -> Project bytecode version为1.7,没有任何效果。

  • File -> Other Settings -> Default Project Structure -> Project SDK and Project language level set to the Java 7 SDK. File -> Other Settings -> Default Project Structure -> Project SDK and Project language level设置为Java 7 SDK。 Message tab still displays: Information:Using javac 1.8.0_112-release to compile java sources 消息选项卡仍显示: Information:Using javac 1.8.0_112-release to compile java sources

Has anyone else experienced this and know what causes this behaviour? 有没有其他人经历过这种情况并知道导致这种现象的原因?

Apparantley this was caused by an issue in IntelliJ as stated in this issue. Apparantley这是由在的IntelliJ一个问题,因为在规定造成这个问题。

It has been resolved as of IntelliJ IDEA version 2016.3.1 and I copy-paste the comment from Eugene Zhuravlev in the youtrack issue to explain how it has been fixed: 自IntelliJ IDEA版本2016.3.1起已解决,我复制并粘贴了尤金·朱拉夫列夫( Eugene Zhuravlev)在Youtrack问题中的评论,以解释其解决方法:

A new compiler option has been introduced for javac: File | 为Javac引入了新的编译器选项: Settings | 设置| Build, Execution, Deployment | 构建,执行,部署| Compiler | 编译器 Java Compiler | Java编译器| "Use compiler from module target JDK when possible". “尽可能使用来自模块目标JDK的编译器”。 The default value is "on". 默认值为“ on”。 When this property is enabled and JDK associated with the module differs from the build's own JDK, the build will prefer compiling with the javac from the associated JDK rather than the compiler from the JDK it runs on. 启用此属性并且与模块关联的JDK与内部版本的JDK不同时,内部版本将更喜欢使用来自相关JDK的javac进行编译,而不是使用运行于其上的JDK的编译器。

You need to set 2 things: 您需要设置两件事:

CTRL + ALT + SHIFT + S --> Project --> Project SDK CTRL + ALT + SHIFT + S- >项目-> Project SDK

CTRL + SHIFT + A --> Type "Java Compiler" --> Target Bytecode Version CTRL + SHIFT + A- >键入“ Java编译器”->目标字节码版本

there is a distiction between Project Structure and Default Project Structure (the latter is for newly created/checked out Projects). Project StructureDefault Project Structure之间存在区别(后者用于新创建/签出的项目)。

Default Project Structure hides in File -> Other Settings . Default Project Structure隐藏在“ File -> Other Settings There you would have Project SDK and Project Language Level . 在那里,您将拥有Project SDKProject Language Level

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM