今天要将一个项目的jdk由1.6的版本变更为1.8的版本。
我将eclipse的Preference -> Java -> Instanled JREs 里面的jdk改为jdk1.8,将Preference -> Java -> Compiler 里面的1.6改为1.8.
为了让项目在eclipse里面刷新,我使用快捷键“ALT + F5”刷新了项目。结果,我发现eclipse的Instanled JREs 和Compiler 有变更为jdk1.6 。我以为eclipse有啥问题呢,重复尝试了好几次,发现还是这个样子。
于是乎我就去万能的Google搜索了一下。发现了有人和我遇到了同样的问题。
地址如下:
http://stackoverflow.com/questions/9926798/eclipse-jre-system-library-j2se-1-5
内容如下:
------------------------------------------------------------------------------------------------------------------------------
|
I'm using Eclipse EE 3.7 with m2e plugin installed. I have JDK7 set in eclipse. When I import maven projects, the JRE is set to JRE System Library [J2SE-1.5] , So i have compilation issues with java 6 related stuff. Instead I want the JRE in eclipse to be by default set to JRE System Library [J2SE-1.6]
When i try to open a new project in eclipse File -> new -> Java project on the first screen i have an option to choose JRE and the third option is Use default JRE (currently 'jdk1.7.0_03')
From this i can see that the default JRE in Eclipse is 1.7, but when i import new Maven projects, the JRE is set to 1.5 by default.
Any help, how can i do this?
|
|
asked Mar 29 '12 at 13:53
|
|
|
|
|
The problem is not with Eclipse, but with the projects you're importing. m2e will set the project's JRE to match the maven project. The POM specifies the JRE version, and this is defaulted to 1.5 if not present. You need this in the POM:
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.0</version><configuration><source>1.7</source><target>1.7</target></configuration></plugin></plugins></build>
|
|
answered Mar 29 '12 at 14:14
|
|
|
|
|
artbristol gave the correct answer (and I upvoted him).
That was in 2012. Here is an update more appropriate for today (2016, Java 8, Spring 4.x/Servlet 3.x):
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.0</version><configuration><source>1.7</source><target>1.7</target></configuration></plugin>
|
|
|
------------------------------------------------------------------------------------------------------------------------------
按照上面的提示,我将项目的pom.xml的
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
修改一下就好了。如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
分享到: