How to run my first kotlin "Hello world"

Dear Friends,
Today is my first day in Kotlin study. I installed kotlin compiler and try to run my first code

fun main()
{
  println("First Program")
}

I created my jar file using command

D:\Kotlinplay>kotlinc First.kt -include-runtime -d first.jar

successfully created first.jar file

but when I try to run using command

D:\Kotlinplay>java -jar first.jar
no main manifest attribute, in first.jar

How to solve this issue ?

Please advise ASAP.

Thanks
Anes P A

If this is your first day in Kotlin and you don’t have experience with Java as well (your problem is more really about the Java, not Kotlin), then I suggest you to use a proper IDE like IntelliJ and it will do this for you. Running compilers and executing manually is a kind of advanced usage, it requires some additional knowledge.

Short answer is to run this instead:

java -cp first.jar FirstKt

But still, I think IDE will be much easier for you. Alternatively, create a very basic gradle build script.

Thanks @broot
but when I run
D:\Kotlinplay>java -cp first.jar FirstKt

Error: Main method not found in class FirstKt, please define the main method as:
public static void main(String args)
or a JavaFX application class must extend javafx.application.Application

Please tell how to solve.

Thanks
Anes P A

You can try to use this instead:

fun main(args: Array<String>) {

But I think that shouldn’t be required.

1 Like

Thanks alor dear @broot
Your advise works
now code is

fun main(args: Array<String>)
{
  println("First Program help by Broot")
}

Thanks

Anes P A