When I was playing with Java personally, I was a little addicted to it. It may be a relatively basic thing, but I didn't know it, so I'll write it down as a memorandum. (Because I have a lot of knowledge gained from qualifications, I'm quite missing this kind of practical part ...)
When Maven project update is executed, it is compiled with JDK 1.5, so a program written with the syntax of JDK 1.6 or later will cause a compilation error.
Details below.
Prior state. The JRE System Library is set to 1.8.
Right click ⇒ Maven ⇒ Run Update Project (Or Alt + F5)
The JRE System Library is changed to 1.5.
Since 1.5, try-with-resources introduced in 1.7 is a compile error
The diamond operator was introduced from 1.7, so a compile error (It is said that the type should be specified on the right side or JRE 1.7)
Looking at the following site, it seems that the default compiler version of the Maven project is 1.5.
-How to specify the JDK version with Maven [JDK 1.5-> 1.8] -Maven: Compiler version setting -Setting the -source and -target of the Java Compiler
Refer to what is written in Apache Maven site, pom. Modify xml. By doing this, you can specify the version of JRE. There are the following methods ① and ②, but this time we will implement ①.
Specify 1.8 this time.
pom.xml
<properties>
・ ・ ・
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
・ ・ ・
</properties>
I haven't written this way this time, but it seems that I can still go.
pom.xml
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
After correcting ① (or ②) above, right-click again ⇒ Maven ⇒ Execute Update Project (Or Alt + F5) ⇒ JRE System Library becomes 1.8.
Confirm that the try-with-resources compilation error has been resolved.
The diamond operator compilation error has also been resolved.
that's all.