Eclipse JRE系统库[J2SE-1.5]

时间:2021-11-05 10:43:09

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]

我正在使用安装了m2e插件的Eclipse EE 3.7。我在Eclipse中设置了JDK7。当我导入maven项目时,JRE设置为JRE系统库[J2SE-1.5],所以我有与java 6相关的东西的编译问题。相反,我希望eclipse中的JRE默认设置为JRE系统库[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')

当我尝试在第一个屏幕上的eclipse文件 - >新建 - > Java项目中打开一个新项目时,我可以选择JRE,第三个选项是使用默认JRE(当前为'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.

从中我可以看到Eclipse中的默认JRE是1.7,但是当我导入新的Maven项目时,JRE默认设置为1.5。

Any help, how can i do this?

任何帮助,我该怎么办?

2 个解决方案

#1


76  

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:

问题不在于Eclipse,而在于您要导入的项目。 m2e将设置项目的JRE以匹配maven项目。 POM指定JRE版本,如果不存在,则默认为1.5。你需要在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>

#2


6  

artbristol gave the correct answer (and I upvoted him).

artbristol给出了正确答案(我赞成他)。

That was in 2012. Here is an update more appropriate for today (2016, Java 8, Spring 4.x/Servlet 3.x):

那是在2012年。这是一个更适合今天的更新(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>

#1


76  

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:

问题不在于Eclipse,而在于您要导入的项目。 m2e将设置项目的JRE以匹配maven项目。 POM指定JRE版本,如果不存在,则默认为1.5。你需要在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>

#2


6  

artbristol gave the correct answer (and I upvoted him).

artbristol给出了正确答案(我赞成他)。

That was in 2012. Here is an update more appropriate for today (2016, Java 8, Spring 4.x/Servlet 3.x):

那是在2012年。这是一个更适合今天的更新(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>