Skip to content
Menu
e-lo [IT Engineer life]
  • Home
    • Notes
    • Important notes
  • Database
    • T-SQL
    • SQL Server quick
    • SQL server docs
    • MySql quick sheet
    • Postgre
    • InfluxDB
  • Programming
    • MS Azure Powershell
    • MS Azure Command-Line Interface (CLI) doc
    • Python Docs
    • Python Logging
    • Python-cheat-sheet
    • Git-guide
  • Azure
    • MS Windows virtual machines in Azure
    • MS ARM Docs
    • MS ARM Template Docs
    • MS ARM Functions
    • MS Bicep+ARM
    • MS ARM Tutorial
    • MS Deployment scripts (intern/extern)
    • MS Virtual Network
  • Az-nutshell
    • ms-technology-choices-compute-decision-tree
    • ms-data-store-decision-tree
    • ms-data-explorer
    • ms-storage-explorer
    • ms-azure-sql
    • ms-common-data-services
    • ms-azure-mysql-daas
    • ms-sla
    • az paas
    • az glossary-quicksheet
    • az-test-vm-script-quickguide
  • Linux
    • Top CMD’s
    • Useful CMD Linux
    • ss64 Linux
    • Ubuntu
    • 30 things Ubuntu 18.04
    • Bootable Ubuntu USB
    • LinuxFilesystemTreeOverview
  • Sys Admin
    • System Administrator
    • Sys News
    • Packet Sniffers
  • Zen
    • Not thinking about anything is Zen
e-lo [IT Engineer life]

5 min Kotlin and AdopOpenJDK and make jar (Extended import java.util.*)

Posted on December 18, 2021December 21, 2021 by espenk

Files after download

Download AdoptOpenJDK


AdoptOpenJDK – Open source, prebuilt OpenJDK binaries


OpenJDK11U-jdk_x64_windows_hotspot_11.0.13_8.msi

On install:
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

Download Kotlin zip


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


kotlin-compiler-1.6.10.zip unzip it somewhere

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

Add KOTLIN_HOME and Path


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, New and add a new path:
%KOTLIN_HOME%\bin

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

Verify home with cmd

echo %JAVA_HOME%
echo %KOTLIN_HOME%

Yields
C:\Program Files\Eclipse Adoptium\jdk-11.0.13.8-hotspot\
C:\giti2021\Kotlins\kotlin-compiler-1.6.10\kotlinc

Consider project files

Where Main.kt is importing both classes

Compile and run a jar (single class)

# Compile from .
kotlinc -include-runtime -d Main.jar Main.kt
# Run it
java -jar Main.jar

Compile and run a jar (multiple class, will work here since main is referencing 2 classes)

# Compile from .
kotlinc -include-runtime -d Main.jar Main.kt Helper.kt Utility.kt
# Run it
java -jar Main.jar

Result


Note, dependency and red lines in VSC

vscode: cannot access built in declaration. · Issue #153 · fwcd/kotlin-language-server (github.com)

Turns out as soon as I installed gradle, using sdk install gradle, language-server suddenly started functioning as expected. Without adding a gradle project in the directory.

Install Gradle (did not help, but could be nice to learn Gradle)

Gradle | Installation

Microsoft Windows users
Create a new directory C:\Gradle with File Explorer.

Open a second File Explorer window and go to the directory where the Gradle distribution was downloaded. Double-click the ZIP archive to expose the content. Drag the content folder gradle-7.3.2 to your newly created C:\Gradle folder.

Alternatively you can unpack the Gradle distribution ZIP into C:\Gradle using an archiver tool of your choice.

Step 3. Configure your system environment

Microsoft Windows users
In File Explorer right-click on the This PC (or Computer) icon, then click Properties -> Advanced System Settings -> Environmental Variables.

Under System Variables select Path, then click Edit. Add an entry for C:\Gradle\gradle-7.3.2\bin. Click OK to save.

Step 4. Verify your installation
Open a console (or a Windows command prompt) and run gradle -v to run gradle and display the version, e.g.:

Still :

visual studio code – Kotlin, unresolved reference on everything in VSCode – Stack Overflow

Remove Kotlin, but keep kotlin language (did help)

Import java.util.*

Since we are using the JVM from AdoptOpenJDK we can use all libs fra Java.

import java.util.*

class Utility {

    fun getStr(): String {
        return "Utility str"
    }
    
    fun randomJava() {
        var ran = Random()
        var nr  = ran.nextInt(100)
        var fl  = ran.nextFloat()
        println(nr)
        println(fl)
    }  
}

Compile it and run it:

kotlinc -include-runtime -d Main.jar Main.kt Helper.kt Utility.kt
java -jar Main.jar

[]
Hello from VSC
12
WORKER1 28
Utility str
30
0.27628368

RSS Azure

  • MLOps Blog Series Part 3: Testing scalability of secure machine learning systems using MLOps June 30, 2022

RSS RabbitMQ

  • RabbitMQ 3.8.15 release

RSS Python

  • PEP 694: Upload 2.0 API for Python Package Repositories June 11, 2022

Tags

5 min (29) Ansible (1) ARM (10) azure (41) cmd (3) Django (4) Docker (1) e-lo (2) Flask (2) Github (9) Grafana (2) Information (7) Information Retrieval (13) JAVA (1) kivy (2) Kotlin (6) linux (15) mobile (2) Natural Language Prossesing (NLP) (2) Net.Core (1) Networking and Security (9) OPC (2) PEP8 (1) Philosophy (3) Python (48) Python Networking and Security (5) Reason (2) RMQ (3) Solr (11) Sql (10) Uncategorized (2) VSC (1) Warframe (2) WMVARE (4) Zabbix (7)

Recent Posts

  • 401 access denied win server (iis), Local Security Policy
  • Callback
  • Share-level permissions IAM Azure AD
  • Packet Sniffers
  • MSA Account

Archives

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Photo by Markus Spiske from Pexels "Matrix"

©2022 e-lo [IT Engineer life] | Powered by WordPress & Superb Themes