简体   繁体   English

如何将默认的Eclipse Oxygen编译器合规性级别从9更改为1.8,而不是将其恢复为9?

[英]How do I change the default Eclipse Oxygen compiler compliance level from 9 to 1.8 and not have it revert back to 9?

When I open a workspace in Eclipse Oxygen , the default compiler compliance level is set to 9 . 当我在Eclipse Oxygen打开工作空间时,默认的编译器合规性级别设置为9 I change it in Preferences > Java > Compiler back to 1.8 and click Apply. 我在Preferences > Java > Compiler中将其更改回1.8 ,然后单击Apply。 It works, until I close Eclipse and reopen it and now it's back to 9 . 它工作,直到我关闭Eclipse并重新打开它,现在它又回到了9 How can I make the change stick? 我怎样才能改变这个变化?

Note: I know that /instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.compliance is set somewhere to 9, but I can't find out where that is. 注意:我知道/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.compliance设置为9,但我找不到它的位置。

I cannot replicate your problem of compliance changes not persisting across restarts, but you can manually set them rather than using Eclipse's GUI. 我无法复制合规性更改的问题,而不是在重新启动时保持不变,但您可以手动设置它们而不是使用Eclipse的GUI。 To do that: 要做到这一点:

  • Close Eclipse. 关闭Eclipse。
  • Locate your preferences file. 找到您的首选项文件。 This is a text file containing many of settings you normally assign in Eclipse using Window > Preferences . 这是一个文本文件,其中包含您通常使用Window> Preferences在Eclipse中分配的许多设置。 The file will be in your workspace directory within the .metadata directory with the following name: 该文件将位于.metadata目录中的workspace目录中,其名称如下:

    .metadata.plugins\\org.eclipse.core.runtime.settings\\org.eclipse.jdt.core.prefs .metadata.plugins \\ org.eclipse.core.runtime.settings \\ org.eclipse.jdt.core.prefs

  • Open the file org.eclipse.jdt.core.prefs in a text editor and edit the following three lines: 在文本编辑器中打开文件org.eclipse.jdt.core.prefs并编辑以下三行:

org.eclipse.jdt.core.compiler.codegen.targetPlatform=9 org.eclipse.jdt.core.compiler.codegen.targetPlatform = 9

org.eclipse.jdt.core.compiler.compliance=9 org.eclipse.jdt.core.compiler.compliance = 9

org.eclipse.jdt.core.compiler.source=9 org.eclipse.jdt.core.compiler.source = 9

  • Replace the three instances of "9" with "1.8" for JDK 1.8 compliance (or "10" for JDK 10 compliance). 将“9”的三个实例替换为“1.8”以符合JDK 1.8(或“10”符合JDK 10)。 Those three properties correspond to the three fields you see on the Compiler screen which specify a version, as shown below. 这三个属性对应于您在“ 编译器”屏幕上看到的指定版本的三个字段,如下所示。
  • Restart Eclipse and go to Preferences > Java > Compiler . 重新启动Eclipse并转到Preferences> Java> Compiler The settings for the compiler should now all be set to 1.8: 现在,编译器的设置都应设置为1.8:

complianceGUI

This approach worked for me. 这种方法对我有用。 However, even if this approach solves your problem, you could still raise a Bug Report with Eclipse since it should not be necessary to manually edit the preferences file. 但是,即使这种方法解决了您的问题,您仍然可以使用Eclipse引发错误报告,因为不需要手动编辑首选项文件。

My workspace settings were getting over-written by user-specific settings stored in ~/.eclipse/org.eclipse.oomph.setup/setups/user.setup . 我的工作区设置被存储在~/.eclipse/org.eclipse.oomph.setup/setups/user.setup的用户特定设置~/.eclipse/org.eclipse.oomph.setup/setups/user.setup Specifically, that file included those leftover setup lines from a previous installation: 具体来说,该文件包含以前安装的剩余设置行:

<setupTask
      xsi:type="setup:PreferenceTask"
      key="/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.codegen.targetPlatform"
      value="9"/>
  <setupTask
      xsi:type="setup:PreferenceTask"
      key="/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.compliance"
      value="9"/>
  <setupTask
      xsi:type="setup:PreferenceTask"
      key="/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.source"
      value="9"/>
</setupTask>

Solution: Remove the lines above from ~/.eclipse/org.eclipse.oomph.setup/setups/user.setup . 解决方案:~/.eclipse/org.eclipse.oomph.setup/setups/user.setup删除上面的行。

Note: Thanks to @skomisa who helped me figure this out. 注意:感谢@skomisa帮我解决了这个问题。

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

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