I have followed the tut here http://sparkjava.com/documentation.html#getting-started
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>spark</groupId>
<artifactId>Spark</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spark</name>
<description>spark</description>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</project>
Hello.java
import static spark.Spark.*;
public class Hello {
public static void main(String[] args) {
get("/hello", (req, res)-> "Hello World");//eclipse error this line
}
}
I got an error with eclipse
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
req cannot be resolved to a variable
Syntax error on token ",", . expected
Syntax error on token "-", -- expected
at Hello.main(Hello.java:5)
Java's lambda expressions are a feature in Java 8: Oracle link . You'll need to change your compliance level (and java version, and pom) to java 8 to make this example compile.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.