在 eclipse(sts) 中更改为 jdk 7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8211384/
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
Change to jdk 7 in eclipse(sts)
提问by Aubergine
How do I switch project from JDK 6 to 7, I know I am not using it because switch doesn't accept String.
如何将项目从 JDK 6 切换到 7,我知道我没有使用它,因为 switch 不接受 String。
In build path I have jre 7 in compiler settings I have 1.7 , everywhere and it still doesn't work. I use Spring Tool Suite(Eclipse based) latest version which officially supports Java 7.
在构建路径中,我在编译器设置中有 jre 7 我有 1.7 ,到处都是,但它仍然不起作用。我使用官方支持 Java 7 的 Spring Tool Suite(基于 Eclipse)的最新版本。
And in project facets I also have 1.7. Why it has to be so bloody difficult.
在项目方面,我也有 1.7。为什么它必须如此血腥困难。
And in .ini I have perfectly correct C:\Program Files\Java\jdk1.7.0\bin\javaw.exe -startup
在 .ini 我有完全正确的 C:\Program Files\Java\jdk1.7.0\bin\javaw.exe -startup
And I am sure my IDE supports 7 because whenever I create new project I have not syntax errors with String switch statement.
而且我确信我的 IDE 支持 7,因为每当我创建新项目时,我的 String switch 语句都没有语法错误。
And my JAVA HOME set to JDK 1.7 :-)
我的 JAVA HOME 设置为 JDK 1.7 :-)
UPDATE: The problem only happens with projects of Spring nature.
更新:这个问题只发生在 Spring 性质的项目中。
UPDATE 2: Happens with template Spring MVC project, Spring Hibernate template apparently works with Java 7.
更新 2:发生在模板 Spring MVC 项目中,Spring Hibernate 模板显然适用于 Java 7。
Totally confused.
完全糊涂了。
回答by mliebelt
When I start a new Java project in Eclipse Indigo, eclipse tells me that the compiler compliance level 1.7 is not supported:
当我在 Eclipse Indigo 中启动一个新的 Java 项目时,eclipse 告诉我不支持编译器合规性级别 1.7:


It is not possible to change that from inside eclipse, the properties dialog shows that:
无法从 eclipse 内部更改它,属性对话框显示:


So as a result, it is not possible to use the new switch statement with Strings in it:
因此,无法使用包含字符串的新 switch 语句:


See the "Eclipse Forums Post"for more information about the topic. It seems that it will come only with the next eclipse version.
有关该主题的更多信息,请参阅“Eclipse 论坛帖子”。看来它只会在下一个eclipse版本中出现。
回答by Peter Szanto
In window / preferences / Installed JREs you need to have the JDK1.7 as the default set up. Additionally in Project / Properties Java Compiler it should be also set (or disable the project specific settings)
在窗口/首选项/已安装的 JREs 中,您需要将 JDK1.7 作为默认设置。此外,在 Project / Properties Java Compiler 中也应该设置它(或禁用项目特定的设置)
UPDATE :
更新 :
In my .settings folder there is a file called org.eclipse.wst.common.project.facet.core.xml
在我的 .settings 文件夹中有一个名为 org.eclipse.wst.common.project.facet.core.xml 的文件
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.6"/>
<installed facet="jst.web" version="2.4"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
and contains some rather suspicious values. Not sure it matters, but worth trying to close the project change it then reopen the project. If that doesnt help then search for the string 1.6 in all files in your project
并包含一些相当可疑的值。不确定它是否重要,但值得尝试关闭项目更改它然后重新打开项目。如果这没有帮助,则在项目的所有文件中搜索字符串 1.6
回答by Wojtek Owczarczyk
Compare .classpathand .projectfiles between your simple Java projects and Spring projects. Sometimes the Natureor other project setting can be set differently.
比较.classpath和.project你简单的Java项目和Spring项目之间的文件。有时,自然或其他项目设置可以设置不同。

