LoginSignup
0
1

More than 3 years have passed since last update.

Gradleで動かすKotlin版のSparkFrameworkのプロジェクトを1から作成

Last updated at Posted at 2018-08-24

JVM言語でイチオシのKotlin版の、マイクロフレームワークSparkFrameworkのHelloWorldプロジェクトを作成します。

前提

  • JVM 1.8
  • Grade 4.9

手順

まず、プロジェクト用のディレクトリを作成し、gradle initで初期化します。

mkdir sparkjava_sample
cd sparkjava_sample
gradle init

build.gradleを編集します。

build.gradle
plugins {
    id "org.jetbrains.kotlin.jvm" version "1.2.61"
}

apply plugin: 'application'

mainClassName = 'com.example.MainKt'

repositories {
    jcenter()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8"
    compile "com.sparkjava:spark-kotlin:1.0.0-alpha"
}

メインクラスを作成します。

mkdir -p src/main/kotlin/com/example
touch !$/Main.kt
Main.kt
package com.example;

import spark.kotlin.*

fun main(args: Array<String>) {
    val http: Http = ignite()

    http.get("/hello") {
        "Hello Spark Kotlin!"
    }
}

サーバーを実行します。

./gradlew run

> :runと表示されたら http://localhost:4567/hello にアクセスし、Hello Spark Kotlin!と表示されれば :ok:

参考

0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1