Peter03/25/2023, 2:43 PM
fun main(args: Array<String>)
will produce the
kotlinc Main.kt include-runtime -d Main.jar
, and the
need to be called. Why
java -jar Main.jar
in the Kotlin case? The
suffix is normally only produced for Java? b) if the main function lives inside an
, that function needs to be annotated w/
, but then it can be called w/
suffix (as a
does not exist). This still is not sufficient for Java (albeit the annotation), as the runtime dependency needs to be added again.
Vampire03/25/2023, 2:49 PM
file are not in any class, so an artifical class called
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
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
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.
Peter03/25/2023, 4:31 PM
Vampire03/25/2023, 5:15 PM
Hey @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
it is still run by Java. Or you could still use it as library in some other Java project. ...
java -jar ...
And how would the classpath look like, without packaging the stuff into a JAR?Depends on which of the runtime libraries you use. That
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
plugin in Gradle.