Recently, I was working in a project and I coded a multi-catch statement because…you know…they’re cool. Multi-catches were introduced in Java 1.7 and are not therefore supported with a compiler below 1.7. Duh-doy! But I’ve got it covered, right? My Eclipse IDE is configured to use a 1.8 JDK. My project is configured to compile with 1.8. So why am I getting this message?
multi-catch statement is not supported in -source 1.5
(use -source 7 or higher to enable multi-catch statement)
I’ve been using maven with eclipse for 4 years and I’ve never run into this problem because a certain bit of config was always there and I didn’t know it. I found this statement at maven.apache.org
Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.
This is how independent Maven is. It doesn’t care a lick about your IDE configuration or your local JDK. If you do not tell it to compile at a particular version, it will run by default at 1.5. If you’re having this problem, the solution is very simple. Add the following text to the plugins tag of your project pom.xml.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin
Now you can multi-catch, lambda, and stream with the cool kids!
Thanks for reading! If you would like to see what else I’m up to, check out Whiff
You can also resolve this problem by using below steps for Eclips user and can be work for IntelliJ as well-
Right click on the project and select Buid Path then Configure Build Path..
Select Project Facets under Maven.
Then select Java version as 1.8 and apply ok.