2

How do I build HelloWorld.kt as a JAR so that it runs?

thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ kotlinc HelloWorld.kt --include-runtime -d HelloWorld.jar
error: invalid argument: --include-runtime
info: use -help for more information
thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ kotlinc HelloWorld.kt -d HelloWorld.jar
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.util.text.StringFactory to constructor java.lang.String(char[],boolean)
WARNING: Please consider reporting this to the maintainers of com.intellij.util.text.StringFactory
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ java -jar HelloWorld.jar 
no main manifest attribute, in HelloWorld.jar
thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ cat HelloWorld.kt 
import kotlin.jvm.JvmStatic

object HelloWorld {
    @JvmStatic
    public fun main(args: Array<String>) {
        println("Hello, world!" + args[0])
    }
}
thufir@dur:~/kotlin$ 

Note that it's declared as a class, and so the method is not on the top level(?). Would want to include the kotlin runtime as well.

Do I need to manually create a MANIFEST.MF with Main-Class for the entry point?

Thufir
  • 8,216
  • 28
  • 125
  • 273

1 Answers1

1

You should use a build tool like Gradle for that task.

In this example, a Jar with Manifest entry is being created: https://github.com/s1monw1/kotlin_vertx_example/blob/master/build.gradle.kts

s1m0nw1
  • 76,759
  • 17
  • 167
  • 196
  • does kotlin allow or work with shadowJar? Is this an odd way to build and package kotlin? Thanks for the sample build :) will have to adapt it, then accept. – Thufir Oct 27 '17 at 17:03
  • 1
    Sure you can work with shadowJar, you’ll find examples – s1m0nw1 Oct 27 '17 at 17:04
  • to use shadowJar I narrowed the scoped of the question as: https://stackoverflow.com/q/47121264/262852 and will review your answer. thanks again :) – Thufir Nov 05 '17 at 11:59