`
kanpiaoxue
  • 浏览: 1781795 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

eclipse指定jdk1.8,之后使用maven刷新jdk版本变为历史版本的问题

 
阅读更多

 

今天要将一个项目的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?

shareimprove this question
 
    
I am experiencing a similary problem. Whatever the JRE System Library is set to, performing a Project>Maven>Update Project... resets the JRE System Library to J2SE-1.5. – mbmast Dec 3 '15 at 18:14

2 Answers

up vote61down voteaccepted

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>
shareimprove this answer
 
    
It works, thanks – sinisa229 mihajlovski Mar 29 '12 at 15:11
1  
Here is some more info from Maven site – Saik0 Nov 14 '13 at 8:59
    
for people who have more than one project this question could also be of intereststackoverflow.com/questions/2531650/… – Xtroce Mar 26 '14 at 14:37
    
I put it in <build><plugins></plugins></build> of pom file. It works, thanks! – Jugal Panchal Jul 12 '15 at 20:39
 

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>
shareimprove this answer
 

------------------------------------------------------------------------------------------------------------------------------

 

按照上面的提示,我将项目的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>

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics