adierebel / Spark Java Starter Kit

05 Sep 2018 at 06:39

Dependencies

compile "com.sparkjava:spark-core:2.7.2"
compile 'org.slf4j:slf4j-simple:1.7.25'

Build JAR - Gradle Task

jar {
    baseName = project.name + '-all'
    manifest {
        attributes "Main-Class": "com.snipnyet.api.Main"
    }
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}
1 package com.snipnyet.api;
2
3 import static spark.Spark.*;
4
5 public class Main {
6 public static void main(String[] args) {
7 // IP Address & Port
8 ipAddress("127.0.0.1");
9 port(8080);
10
11 // Thread
12 int maxThreads = 8;
13 int minThreads = 2;
14 int timeOutMillis = 30000;
15 threadPool(maxThreads, minThreads, timeOutMillis);
16
17 // Init app
18 init();
19
20 // Routes
21 get("/", (request, response) -> {
22 return "<h1>Hello</h1>";
23 });
24 }
25 }

Comments (0)