1

I want to export my kotlin program to a runnable file (be it .jar, .exe, whatever) so that other people will be able to use my programs, however I can't figure out how to do this. I'm using IntelliJ Community edition

My only code is a file called Main.kt containing:

fun main() {
    println("Hello World")
}

I understand I need to set up an artifact, but I'm not sure what to put in the artifact settings, and when I build it as shown here, the .jar file doesn't output anything.

What am I doing wrong?

Edit: After running java -jar "Simple Kotlin Test_jar.jar" it comes back with no main manifest attribute, in Simple Kotlin Test_jar.jar

Rolodophone
  • 813
  • 1
  • 7
  • 10
  • Did you try to run it using `java -jar "filename.jar"` command? By default `.jar` file may be associated with `javaw` on Windows which doesn't have a console for the output and is normally used for the GUI apps. In order to get the console output you need to run it with `java` instead of `javaw` command. – CrazyCoder May 03 '19 at 17:49
  • Edited question – Rolodophone May 03 '19 at 17:55
  • See https://medium.com/@preslavrachev/kotlin-basics-create-executable-kotlin-jars-using-gradle-d17e9a8384b9. You need to specify the main class as `MainKt` in this case for the jar mainfest. – CrazyCoder May 03 '19 at 18:25
  • See also https://stackoverflow.com/a/54894502/104891. Make sure the manifest specifying the `Main-class: MainKt` is at the top. – CrazyCoder May 03 '19 at 18:32
  • Thanks, it worked! If you add your comment as an answer ill tick it – Rolodophone May 03 '19 at 20:06

1 Answers1

1

You need to define the Main-class for the jar manifest. In this case it would be MainKt.

Make sure this manifest is at the top of the artifact so that other jars don't override it.

The app should be also started using java -jar jarname.jar to get the console output, otherwise it will use javaw and you will not see the output.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904