gradle
  • kotlin
  • 2016-09-19 201 views 6 likes 
    6

    科特林應用正確的方法我已經有了簡單的腳本運行的gradle從任務

    package com.lapots.game.journey.ims.example 
    
    
    fun main(args: Array<String>) { 
        println("Hello, world!") 
    } 
    

    這裏是gradle任務

    task runExample(type: JavaExec) { 
        main ='com.lapots.game.journey.ims.example.Example' 
        classpath = sourceSets.main.runtimeClasspath 
    } 
    

    但是當我嘗試運行任務gradle runExample我得到錯誤

    Error: Could not find or load main class com.lapots.game.journey.ims.example.Example

    什麼是正確的WA ❖運行應用程序?

    +4

    的可能的複製[如何運行科特林編譯後的class文件?(http://stackoverflow.com/questions/9355690/how-to-run-compiled-class-file-in-kotlin) –

    +1

    有一個關於使用Gradle應用程序插件運行Kotlin應用程序的部分:http://stackoverflow.com/a/26402542/3679676 ...或者你是否需要它運行 - 如果它是一種其他方式的任務?但是這個答案也可以給你你需要的線索。 –

    回答

    3

    感謝鏈接how to run compiled class file in Kotlin?通過@JaysonMinard 是main

    @file:JvmName("Example") 
    
    package com.lapots.game.journey.ims.example 
    
    
    fun main(args: Array<String>) { 
        print("executable!") 
    } 
    

    提供和task

    task runExample(type: JavaExec) { 
        main = 'com.lapots.game.journey.ims.example.Example' 
        classpath = sourceSets.main.runtimeClasspath 
    } 
    

    的伎倆

    0

    您還可以應用的Gradle插件此。

    // example.kt 
    package com.lapots.game.journey.ims.example 
    
    fun main(args: Array<String>) { 
        print("executable!") 
    } 
    

    添加到您的build.gradle

    // build.gradle 
    apply plugin "application" 
    mainClassName = 'com.lapots.game.journey.ims.example.ExampleKt' 
    

    然後運行你的應用程序如下。

    ./gradlew run 
    
    相關問題