njk2015 njk2015 - 1 year ago 96
Java Question

Maven compilation of my Java 8 source code fails

On my mac, I am trying to compile some Java 8 source code I wrote. It compiles fine in Eclipse, but in Maven, the compilation is failing.

I get multiple errors of the form:

[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] /Users/admin/eclipse/workspaces/default/Java8/src/main/java/language/utilities/MapDemo.java:[14,33] lambda expressions are not supported in -source 1.7
(use -source 8 or higher to enable lambda expressions)

Running mvn -v yields:

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /Users/admin/apache-maven-3.3.9
Java version: 1.8.0_91, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre
Default locale: en_IE, platform encoding: UTF-8
OS name: "mac os x", version: "10.12", arch: "x86_64", family: "mac"

Running the export command shows that the JAVA_HOME variable is set to:


What is this '-source' property? Why do I need to set it if my Java version is Java 8?

Answer Source



in the properties of your pom.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download