I have the following code:
package com.mongoDB;
import spark.Spark;
public class HelloWorldSparkStyle {
public static void main(String[] args) {
Spark.get("/hello", (req, res) -> "Hello World");
}
}
It runs fine when I run it through main method but throws the following error when I try to compile it:
\HelloWorldSparkStyle.java:[9,33] error: lambda expressions are not supported in -source 1.5
D:\WorkspaceWithJava8\BeginnerProject>javac -version
javac 1.8.0_60
I am using Eclipse IDE and trying to compile it through command line.
Let me elaborate above answer further. Put the plugin given in above answer between
<project>
and</project>
as below.By default, the
maven-compiler-plugin
uses Java 5 to compile the classes. Quoting its documentation:You need to configure it to use Java 8, like this: