user3467471 user3467471 - 3 months ago 11
Java Question

mvn complains about java source, even if the required one will be used

it seems really strange, but when I try to build a jar/war file with a mvn command 'mvn clean install' it says, that some functions in code (e.g. try-catch) is not supported in source 1.5., even if I use in my IDE Java 1.8 Library as source and everything will be executed perfectly in Eclipse.

Maven home: /usr/share/maven3
Java version: 1.8.0_91, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre


What can be a problem?

Thanks a lot!

Answer

I can see some problems there:

Please have a look at your maven-compiler-plugin configuration. There it should say something like

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

Because I am afraid you have the wrong source/target configuration in your pom.xml. Make sure both say '1.8'

By the way, I would use a JDK, not a JRE as JAVA_HOME when trying to compile. Please try something like export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64