Instructions for complete Hello World?

Hi,

I am not able to find instructions on how to compile a Hello World program and run it using a “Standalone compiler” from a command line. Is that hidden somewhere?

By trial and errors, I did something like this. Is there an easier way?

``

bash> cd $HOME
bash> unzip kotlin-0.4.68.zip
bash> chmod a+x kotlinc/bin/*

bash> cat << ‘EOM’ > Hello.kt
fun main(args : Array<String>) {
  println(“Hello”)
}
EOM

bash> kotlinc/bin/kotlinc-jvm -src Hello.kt -jar hello.jar
bash> java -cp “kotlinc/lib/*:hello.jar” namespace
Hello

It would be nice this be part of Getting Started Guide such as here http://confluence.jetbrains.net/display/Kotlin/Getting+Started

Zemian

1 Like

To be honest, the easiest ways to play with Kotlin are to either use Kotlin Web Demo or IntelliJ IDEA plugin. If neither of these options are convenient to you, surely you can use command-line compiler. Unfortunately, it is not documented yet, but you can always run kotlin-jvm with "-help" option to see list of available options. Anyway, we'd better add some simple how-to for it.

The way you found is correct. There is an alternative way of storing compiled program: instead of creating jar, you can have compiled classes in some directory, using “-output <dir>” instead of “-jar <jar-file>”.

that was 2012; now it’s late 2017. is there a simlple gradle/kotlin hello world example?

2 Likes

Looks like the repo on Github have one.

https://github.com/JetBrains/kotlin-examples/tree/master/gradle/hello-world

2 Likes