2017-09-22 1 views
1

Je suis très nouveau pour Kotlin et Ktor et Gradle, voulaient essayer Ktor, donc passé par les étapes expliquées here, et a fini avec ce code et structure représentée dans la capture d'écran:Ktor erreurs Exemple de démarrage

Comme vu il y a beaucoup d'erreur, comment les réparer?

package blog 

import org.jetbrains.ktor.netty.* 
import org.jetbrains.ktor.routing.* 
import org.jetbrains.ktor.application.* 
import org.jetbrains.ktor.host.* 
import org.jetbrains.ktor.http.* 
import org.jetbrains.ktor.response.* 

fun main(args: Array<String>) { 
    embeddedServer(Netty, 8080) { 
     routing { 
      get("/") { 
       call.respondText("My Example Blog", ContentType.Text.Html) 
      } 
     } 
    }.start(wait = true) 
} 

Le fichier build.gradle est généré automatiquement comme:

group 'Example' 
version '1.0-SNAPSHOT' 

buildscript { 
    ext.kotlin_version = '1.1.4-3' 

    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 
    } 
} 

apply plugin: 'java' 
apply plugin: 'kotlin' 

sourceCompatibility = 1.8 

repositories { 
    mavenCentral() 
} 

dependencies { 
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version" 
    testCompile group: 'junit', name: 'junit', version: '4.12' 
} 

compileKotlin { 
    kotlinOptions.jvmTarget = "1.8" 
} 
compileTestKotlin { 
    kotlinOptions.jvmTarget = "1.8" 
} 

enter image description here

Répondre

0

Vous avez incomplète build.gradle de script (dépendances manquantes) - voir here pour plus de détails. Voilà la bonne:

group 'Example' 
version '1.0-SNAPSHOT' 

buildscript { 
    ext.kotlin_version = '1.1.4-3' 

    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 
    } 
} 

apply plugin: 'java' 
apply plugin: 'kotlin' 

sourceCompatibility = 1.8 
ext.ktor_version = '0.4.0' 

repositories { 
    mavenCentral() 
    maven { url "http://dl.bintray.com/kotlin/ktor" } 
    maven { url "https://dl.bintray.com/kotlin/kotlinx" } 
} 

dependencies { 
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version" 
    compile "org.jetbrains.ktor:ktor-core:$ktor_version" 
    compile "org.jetbrains.ktor:ktor-netty:$ktor_version" 
    compile "ch.qos.logback:logback-classic:1.2.1" 
    testCompile group: 'junit', name: 'junit', version: '4.12' 
} 

compileKotlin { 
    kotlinOptions.jvmTarget = "1.8" 
} 
compileTestKotlin { 
    kotlinOptions.jvmTarget = "1.8" 
} 
kotlin { 
    experimental { 
     coroutines "enable" 
    } 
} 
+0

Je suis arrivé cette erreur à l'exécution de l'application: « SLF4J: Impossible de charger la classe « org.slf4j.impl.StaticLoggerBinder » SLF4J:. Défaillant à non-opération (NOP) mise en œuvre de l'enregistreur " –

+0

@HasanAYousef, ce n'est plutôt pas une erreur mais un avertissement. Vous devez également configurer l'enregistreur. – Opal

+0

Merci @ OPal, pouvez-vous m'aider avec la deuxième étape que je veux faire, dans cette question: https://stackoverflow.com/questions/46365605/how-to-create-jar-create-executable-of-the- ktor-embedded-server –