tipsy / spark-websocket

Chat application tutorial using Spark and WebSockets
https://sparktutorials.github.io/2015/11/08/spark-websocket-chat.html
Apache License 2.0
69 stars 56 forks source link

compile fails #2

Closed cswarth closed 8 years ago

cswarth commented 8 years ago

Maven targets Java 1.5 by default, so this example that uses features of Java 1.8 is not going to compile. Did you have some settings in your ~/.m2/settings.xml file that were not captured in this repo?

$ mvn compile 
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building sparksocket 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ sparksocket ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ sparksocket ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to /Users/cswarth/Development/spark-websocket/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/cswarth/Development/spark-websocket/src/main/java/Chat.java:[10,63] diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)
[ERROR] /Users/cswarth/Development/spark-websocket/src/main/java/Chat.java:[21,59] method references are not supported in -source 1.5
  (use -source 8 or higher to enable method references)
[ERROR] /Users/cswarth/Development/spark-websocket/src/main/java/Chat.java:[21,83] lambda expressions are not supported in -source 1.5
  (use -source 8 or higher to enable lambda expressions)
[INFO] 3 errors 
cswarth commented 8 years ago

I fixed this issue by adding the appropriate <configuration> directives to the pom.xml file. While I was at it, I also updated the build to use the latest version of the spark API (v2.5). I had to add an explicit dependency on slf4j-simple or the app would fail at runtime due to lack of a logging implementation.

<?xml version="1.0" encoding="UTF-8"?>
<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>sparksocket</groupId>
    <artifactId>sparksocket</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.sparkjava</groupId>
            <artifactId>spark-core</artifactId>
        <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>com.j2html</groupId>
            <artifactId>j2html</artifactId>
            <version>0.7</version>
        </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.21</version>
    </dependency>
    </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
tipsy commented 8 years ago

Sorry about that, I left target out. I just pushed the change :) Edit: I guess I can migrate to 2.5 while we're at it.