當出現這個錯誤時,原因是之前maven默認項目是JDK5,而maven不再支持java1.5,所以需要我們改成自己的版本。
解決方法:
1、在maven的安裝目錄下,找到conf文件,打開settings.xml文件,在<settings></settings>標簽里插入下面的代碼

<profile> <id>jdk-1.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>
2、點擊File--->setting-->File | Settings | Build, Execution, Deployment-->Compiler-->Java Compiler如下圖,分別修改成自己對應的java版本
3、點擊File--->setting-->Project Structure-->Modules如下圖
如果Moudel SDK沒有的話,則new一個JDK,然后選擇自己的JDK位置就可以了,然后保存即可
此時可以運行了,而且以后也不會出現這個問題