http://localhost:4567/hello に接続したら “Hello World”を返すシンプルなコード。
package yourproduct.appname.application;
import static spark.Spark.*;
public class MainRouter {
public static void main(String[] args) {
get("/hello", (req, res) -> "Hello World");
}
}
mavenの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>yourproduct</groupId>
<artifactId>appname</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<encoding>utf-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
起動コマンドはこんな感じですが、Eclipseを持っていれば右クリック → 実行のみです
mvn package mvn exec:java -Dexec.mainClass="yourproduct.appname.application.MainRouter"


