Hi there! I'm trying to build a simple Hello World...
# intellij
d
Hi there! I'm trying to build a simple Hello World (command line) project in Intellij Idea. But when built, the .jar doesn't work, and I don't get why. When I create my project, I choose Kotlin/JVM under Gradle (see Image 1 in thread). The image 2 is the configuration of my artifact, the image 3 is the code of my Hello World, and the image 4 is the output when I try to run the jar from the command line. Do you have any idea?
Image 1

https://kotlinlang.slack.com/files/UP93BG1NF/FTJL144F2/image.png

Image 2

https://kotlinlang.slack.com/files/UP93BG1NF/FT5T0QGH0/image.png

Image 3
Image 4

https://kotlinlang.slack.com/files/UP93BG1NF/FTLGTL5PH/image.png

c
1. you don't need the object or
@JvmStatic
, just put
fun main()
on the top level of the file:
Copy code
fun main() {
    println("Hello World!")
}
2. if you are using gradle you'll want to configure the jar in gradle instead of IntelliJ 3. I'm not sure what OS you are using, but usually jars are run from command line with something like
java -jar helloworld.jar
m
If you're using Gradle, look at the application plugin. Docs in Gradle manual. Should do what you want.
d
@Czar 3. You're right, forgot this detail. This brings another issue... My main class isn't recognized, even though I have defined it as you can see in the image 2 above. I also tried to create it using Gradle, but I'm having an issue that I'm unable to resolve. I still prefer the Intellij Idea way, at least for now.
c
@Dylan Take a look at the samples in kotlin repository and read the docs. Here are some useful links which should help. https://kotlinlang.org/docs/reference/using-gradle.html https://github.com/Kotlin/kotlin-examples/tree/master/gradle/hello-world
d
Thanks! Got it working. I'm an Android dev, and I was using implementation instead of compile which apparently caused some issues. Thanks again!
c
you should be using
implementation
or
api
, compile is deprecated for a long time now.
d
Right, I just had both implementation and compile previously