Peter
03/25/2023, 2:43 PMfun main(args: Array<String>)
then kotlinc Main.kt include-runtime -d Main.jar
will produce the MainKt.class
, and the Main.jar
. So kotlin MainKt
or java -jar Main.jar
need to be called. Why MainKt
in the Kotlin case? The Kt
suffix is normally only produced for Java?
b) if the main function lives inside an object
, that function needs to be annotated w/ @JvmStatic
,
but then it can be called w/ kotlin Main
without th Kt
suffix (as a MainKt.class
does not exist).
This still is not sufficient for Java (albeit the annotation), as the runtime dependency needs to be
added again.Vampire
03/25/2023, 2:49 PMFoo.kt
file are not in any class, so an artifical class called FooKt
is generated and the function put there.
If it is inside a class, it is an instance function of that class unless you define it as @JvmStatic
which makes it a static function of that class.
The Kotlin runtime is of course always needed to run a Kotlin program with the Java interpreter just like any other dependency. The --include-runtime
just builds a bad-practice fat-jar with the Kotlin runtime included, so that you do not have to add it to the classpath manually.Peter
03/25/2023, 4:31 PMVampire
03/25/2023, 5:15 PMHey @Vampire Thank you again for your support! If the code is only run by Kotlin, why the hassle generating a *Kt named bytecode file?Who says it is only run by Kotlin? If you run with
java -jar ...
it is still run by Java.
Or you could still use it as library in some other Java project.
...
And how would the classpath look like, without packaging the stuff into a JAR?Depends on which of the runtime libraries you use. That
-include-runtime
just packs everything in afair, even things you don't use or need.
I'd usually simply use a proper build tool, especially Gradle, and let it build a proper distribution, e.g. using the application
plugin in Gradle.