generate class is MainKt
# getting-started
c
generate class is MainKt
k
And what goes wrong with this?
c
I have this
Copy code
java -jar build/libs/files-1.0-SNAPSHOT.jar
Error: Could not find or load main class MainKt
Caused by: java.lang.ClassNotFoundException: MainKt
even if in
build/classes/
I have:
kotlin/main/MainTk.class
k
Ah,
kotlin
and
main
shouldn't actually be part of the package.
Take a look in the generated jar,
MainKt.class
is probably top level.
c
hmm
it looks like this
Copy code
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available

public fun main(args: kotlin.Array<kotlin.String>): kotlin.Unit { /* compiled code */ }
k
Okay but what's the path of that file within the jar?
Probably not
main/kotlin/MainKt.class
c
Screenshot 2018-11-28 at 13.59.13.png
the Main.tk is this
Copy code
package main.kotlin

fun main(args: Array<String>) {
    println("Hello World")
}
Copy code
jar {
    manifest {
        attributes 'Main-Class': 'main.kotlin.MainKt'
    }
    // Add this
    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
}
k
You actually wrote
package main.kotlin
is the source file?
src/main/kotlin
is supposed to be the root package simple smile
c
intellij told me that ๐Ÿ˜„
lol
let me remove that, from code and build
same ๐Ÿ˜•
I will be out of hair soon :((
๐Ÿ‘ด 1
k
So to recap: there's a manifest in your jar that points to the exact right path within the jar?
(don't look at the build folder, actually open the jar with 7zip or something)
c
and look for?
manifest?
k
manifest and the path to
MainKt.class
c
moment
Screenshot 2018-11-28 at 14.13.54.png
this is how it look unzip
manifest:
Copy code
Manifest-Version: 1.0
Main-Class: main.kotlin.MainKt
a
Looks like the sourceSets are overridden to be eclipse style with src folder as the root so main.kotlin package is correct. Also line 46 has no effect since it is overridden by line 48. Also you may want to look into using shadow jar plugin https://github.com/johnrengelman/shadow
k
But the jar end result looks right :/
c
yup
and is working ๐Ÿ˜•
the repo that I clone
insane! ๐Ÿ˜
a
When you decompile main class does it have same main method signature
In the one that's working
c
I'm baffled now ๐Ÿ˜•
anyway, thanks for the time and the help. I guess I will learn and read more about gradle
I'm trying to do a tiny kotlin script -> jar and then use graal to build a native image ๐Ÿ™‚