duckspot / open-study-lounge

a place to learn and share about tech and life
0 stars 0 forks source link

Kotlin executable Jar with IntelliJ #5

Open peter-dobson-ds opened 2 years ago

peter-dobson-ds commented 2 years ago

Peter wants to create an executable Jar that will run a simple program that reads and modifies some files and creates a log file.

He like to start writing in Kotlin.

peter-dobson-ds commented 2 years ago

connect

peter-dobson-ds commented 2 years ago

research

peter-dobson-ds commented 2 years ago

I created kotlinJarHelloWorld program, by combining steps from the two articles:

The steps are:

  1. IntelliJ IDEA, New Project
    • Choose Gradle: Additional Libraries and Frameworks:
      • Java
      • Kotlin/JVM
    • Choose name and folder, option Artifact Coordinates and specify group.id click [Done]
      • wait for Gradle Project to initialize
        • I’ve seen it take as long as 90 seconds
        • Build window top line will show project-name: finished At 12/14/2021 7:23 PM 1 min, 30 sec, 496 ms
  2. Select src/main/kotlin folder
    • right click, New/Package com.ceb.helloworld
      • Kotlin Docs says you don’t have to have put .kt files in paths that represent the package, that the package statement will suffice, but for this to work you do need create the package folders same as Java.
    • right click, New Kotlin Class/File, Kotlin File
      • package com.ceb.helloworld fun main() { println("Hello.") }
  3. menu File/Project Structure…
    • Artifacts, click +, Jar/From modules with dependencies
      • Main Class: com.ceb.helloworld.MainKt
        • just type it in - searching for it is difficult
        • remember Kotlin classes end with Kt
      • click [OK]
  4. menu Build/Build artifacts…