xun su
11/10/2022, 8:39 PMpackage com.xun.kotlin
to the file, notice the error beside the build button. what's wrong with that ? if I comment the line, the error disappear.
I used to be a frontend developer, In javascript, there is no need to add the line like this.ephemient
11/10/2022, 8:44 PMMainKt
was to the package-less name. Now that you've added a package name, that needs to change.ephemient
11/10/2022, 8:45 PMxun su
11/10/2022, 8:59 PMMainKt
, but not Main.kt
?
anyway I removed that line, Yes, now I could build and run the code via IDEA
but how about use command line ?
java -jar path/to/build/libs/result.jar
just show me a error:
then I searched a similar question and get a answer like this
so I add a line to my build.gradle.kts
,:
tasks.withType<Jar> { manifest { attributes["Main-Class"] = "com.xun.kotlin.MainKt" } }
but I got a another error:
xun@xun-Yoga-14sIHU-2021:~/Desktop/kotlin-basic/build/libs$ java -jar kotlin-basic-1.0-SNAPSHOT.jar
Error: Could not find or load main class com.xun.kotlin.MainKt
Caused by: java.lang.ClassNotFoundException: com.xun.kotlin.MainKt
xun su
11/10/2022, 9:00 PMxun su
11/10/2022, 9:01 PMephemient
11/10/2022, 9:01 PMfile.kt
in a FileKt
class for Java compatibility by default (you can choose a different name with @file:JVM name("...")
)ephemient
11/10/2022, 9:02 PMephemient
11/10/2022, 9:04 PMplugins {
application
}
application {
mainClass.set("com.xun.kotlin.MainKt")
}
this will allow you to use ./gradlew run
xun su
11/10/2022, 9:06 PMkotlin-basic-1.0-SNAPSHOT.jar
is in build directory so it has all it's dependencies bundledephemient
11/10/2022, 9:06 PM./gradlew installDist
which will create a directory build/install
containing everything needed, or ./gradlew distZip
or ./gradlew distTar
which will create that bundle in build/distributions
ephemient
11/10/2022, 9:06 PMxun su
11/10/2022, 9:08 PMxun su
11/10/2022, 9:10 PMStephan Schroeder
11/11/2022, 8:56 AMephemient
11/11/2022, 9:00 AMxun su
11/11/2022, 10:00 AM./gradlew build
to build the project and then run it from a JAR file as usual (java -jar <JAR file>
)."
I thought the builded jar file is in build/libs/
, so I went there but still got error: