Intellij IDEA 创建Maven指定JDK版本

2018-05-16  本文已影响10人  7ccc099f4608

解决报错 types are not supported at this language level 5

原因

一般而言,对于IDEA的Maven项目,如果不在pom.xml中指定JDK版本,则会默认使用JDK 1.5,因而不支持正则表达式等操作。

解决方案

pom.xml<project> ...</project>中加入

<profiles>
        <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>
 </profiles>

之后,鼠标对准pom.xml右键,Maven -- Reimport,搞定~

上一篇 下一篇

猜你喜欢

热点阅读