Gradle 如何从命令行使用Kotlin运行spark java
我是Java新手(大概有7年没做过了)。我正在使用Gradle和创建一个简单的hello world应用程序,该应用程序只运行以下内容:Gradle 如何从命令行使用Kotlin运行spark java,gradle,kotlin,spark-java,Gradle,Kotlin,Spark Java,我是Java新手(大概有7年没做过了)。我正在使用Gradle和创建一个简单的hello world应用程序,该应用程序只运行以下内容: import static spark.Spark.*; fun main(args: Array<String>) { get("/hello", (req, res) -> "Hello World!"); } 我在命令行上运行了gradle,它构建成功,但我如何启动服务器,才能转到localhost:4567查看我的Hello
import static spark.Spark.*;
fun main(args: Array<String>) {
get("/hello", (req, res) -> "Hello World!");
}
我在命令行上运行了gradle
,它构建成功,但我如何启动服务器,才能转到localhost:4567
查看我的Hello World
输出?我应该遵循的一般流程是什么
澄清一下:我是出于良心决定使用Kotlin而不是Java。@Aaron我确实想使用Kotlin。更新的问题。似乎你需要参考Gradle文档。顺便说一下,你不需要SRCDIR。默认的
src/main/kotlin
将是finedupes,也包括从gradle运行。
// Apply the kotlin plugin to add support for Kotlin
apply plugin: 'kotlin'
buildscript {
ext.kotlin_version = '1.1.2-4'
repositories {
jcenter()
mavenCentral()
}
sourceSets {
main.kotlin.srcDirs += 'src/main/myKotlin'
main.java.srcDirs += 'src/main/myJava'
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-4'
}
}
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'com.sparkjava:spark-core:2.3'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}