设置通过Maven创建的工程的JDK的版本,更改conf/settings.xml

eclipse提示警告如下:

Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment. 

1.打开settings.xml文件

2.找到profiles标签

3.加入如下配置:

    <profile>   
        <id>jdk1.8</id>    
        <activation>   
            <activeByDefault>true</activeByDefault>    
            <jdk>1.8</jdk>   
        </activation>    
        <properties>   
            <maven.compiler.source>1.8</maven.compiler.source>    
            <maven.compiler.target>1.8</maven.compiler.target>    
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>   
        </properties>   
    </profile> 

以上部分参考自尚硅谷maven视频资料,讲师封捷。

因为maven创建的工程如果不设置的话,每次通过eclipse创建的maven工程的jdk版本都是1.5(包括类库的版本和编译的版本)。通过在pom.xml里面指定jdk版本,或者手动设置jdk版本都可以解决这个问题,但是如果每一个都指定的话就会很繁琐,pom.xml里面的设置方式如下,作用域为当前工程。

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

鼠标右键当前工程选择 Maven -> Update Project...   ,更新当前工程jdk版本

记录在此方便查询

原文地址:https://www.cnblogs.com/kgtone/p/10356355.html