I am using Maven and Java Spark to build a simple webservice.
I am running Java 8.
My (very simple) service:
package com.mycompany.app;
import static spark.Spark.*;
public class HelloWorld {
public static void main(String[] args) {
get("/hello", (req, res) -> "Hello World");
}
}
The pom.xml file:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.simplerelevance.app</groupId>
<artifactId>art2</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>art2</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</project>
When I try to run mvn compile
, my error is:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project art2: Compilation failure: Compilation failure:
[ERROR] /home/pierceg/SR_Repos/ART2/art2_java/art2/src/main/java/com/simplerelevance/app/HelloWorld.java:[3,7] error: static import declarations are not supported in -source 1.3
[ERROR]
[ERROR] (use -source 5 or higher to enable static import declarations)
[ERROR] /home/pierceg/SR_Repos/ART2/art2_java/art2/src/main/java/com/simplerelevance/app/HelloWorld.java:[7,37] error: lambda expressions are not supported in -source 1.3
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
The not supported in -source 1.3
phrasing makes me think that there is something amiss with what java version I'm using. Previously, I was getting the same error but with -source 1.5
, so I changed $JAVA_HOME to /usr/lib/jvm/java-8-oracle/jre/
. Is this what it should be? One of my coworkers agrees with me that the -source should be 1.8.
Edit: mvn -v returns:
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.8.0_51, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.16.0-30-generic", arch: "amd64", family: "unix"