java---source-1-5-中不支持-try-with-resources--解决方法

报错:

1
2
Error:(19, 13) java: -source 1.5 中不支持 try-with-resources
(请使用 -source 7 或更高版本以启用 try-with-resources)

在网上查阅解决方法

  1. File - Project Structure -Project - Language Level 更改为8
    无法解决。
  2. pom.xml 添加dependency
    无法解决。
    1
    2
    3
    4
    <properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
    </properties>
  3. File - Project Structure -Modules- Language Level 更改为8
    解决。