Kotlin

Kotlin and AdoptOpenJDK with compile for jar. (Extended with Eclipse and AdoptOpenJDK)

AdoptOpenJDK – Open source, prebuilt OpenJDK binaries

OpenJDK11U-jdk_x64_windows_hotspot_11.0.13_8.msi

Add to PATH, Set JAVA_HOME on local HD.

C:\Users\jekl>java -version
openjdk version “11.0.13” 2021-10-19
OpenJDK Runtime Environment Temurin-11.0.13+8 (build 11.0.13+8)
OpenJDK 64-Bit Server VM Temurin-11.0.13+8 (build 11.0.13+8, mixed mode

Release Kotlin 1.6.10 · JetBrains/kotlin (github.com)

Download Kotlin

Download and unzip it

C:\giti2021\Kotlins\kotlin-compiler-1.6.10\kotlinc

Click on the Edit environment variables for your account shortcut.

Enter “KOTLIN_HOME” as variable name. Enter the [KOTLIN_INSTALL_DIR] as variable value.

Next, we need to configure the PATH environment variable so we can run Kotlin from a command prompt.

Select the PATH variable. Click on Edit….

Test it

C:\Users\jekl>java -version
openjdk version “11.0.13” 2021-10-19
OpenJDK Runtime Environment Temurin-11.0.13+8 (build 11.0.13+8)
OpenJDK 64-Bit Server VM Temurin-11.0.13+8 (build 11.0.13+8, mixed mode)

C:\Users\jekl>kotlinc -version
info: kotlinc-jvm 1.6.10 (JRE 11.0.13+8)

VSC Install

  • Kotlin Language
  • Code Runner

Edit the main method

Main.kt->run code

Result:

Compile outside of VSC

Kotlin command-line compiler | Kotlin (kotlinlang.org)

c:\giti2021\Kotlins>kotlinc -version
info: kotlinc-jvm 1.6.10 (JRE 11.0.13+8)

c:\giti2021\Kotlins>kotlinc Main.kt -include-runtime -d Main.jar

c:\giti2021\Kotlins>java -jar c:\giti2021\Kotlins\Main.jar
Hello from VSC

Change in code, run the same steps

fun main() {
println(“Hello from VSC”)
val inp = 12
println(inp)
}

But if you do changes Code runner just compiles one class.

Lets say you are referencing another class

Main.kt and Helper.kt

The Code runner only compiles, the Main.kt

To make a jar of both, since we are not using Kotlin-native but JVM AdoptOpen

Platforms

Get started with Kotlin/JVM | Kotlin (kotlinlang.org)

Kotlin has 3

  • JVM
  • Javascript
  • Native

c:\giti2021\Kotlins\testbasic>kotlinc -include-runtime -d Main.jar Main.kt Helper.kt
c:\giti2021\Kotlins\testbasic>java -jar Main.jar
Hello from VSC
12
WORKER1

Eclipse with AdoptOpenJDK and Kotlin

Setting up AdoptOpenJDK 11 on Eclipse IDE | by Anupindi RaviShankar | Medium

Downloaded:

eclipse-inst-jre-win64.exe

Ran this install

Enable Kotlin plugin

Eclipse IDE | Kotlin (kotlinlang.org)

To add the Kotlin support to your Eclipse IDE, install the Kotlin Plugin for Eclipse. We recommend installing the Kotlin plugin from Eclipse Marketplace. Open the Help | Eclipse Marketplace… menu and search for Kotlin Plugin for Eclipse:

Once the plugin is installed and Eclipse is restarted, make sure the plugin is installed correctly: open the Kotlin perspective in the menu Window | Perspective | Open Perspective | Other…

Press Kotlin and open

Change to AdoptOpenJDK

Configure Eclipse IDE for AdoptOpenJDK
Follow the below steps to configure Eclipse IDE for AdoptOpenJDK
Go to “Windows → Preferences → Java →Installed JREs”
Click on the “Add” button and choose JRE type as “Standard VM”
Select the location of AdoptOpenJDK home & click on Finish button

JAVA_HOME Path:

C:\Program Files\Eclipse Adoptium\jdk-11.0.13.8-hotspot\

Ensure that the Java compiler compliance level is set to 11 as shown below

Now you are ready to create a new Kotlin project.

First, select File | New | Kotlin Project.

Dont mind the error

The project is still there

Now, create a new Kotlin file in the source directory.

Still error…wait

Comments Off on Kotlin and AdoptOpenJDK with compile for jar. (Extended with Eclipse and AdoptOpenJDK)