Member-only story
Prototyping with Kotlin
Java is the King in the Enterprise world. Very often I need some quick prototyping interacting with some Java libraries. But Java is verbose and sometimes a lot of boilerplate codes can not be avoided. When a prototype is required, I often turn to some alternatives. I used to use Jruby, but nowadays I am exploring Kotlin as my 1st choice.
It's preferable and sometimes a must, that the developed prototype/tool has to be run on JVM, which is available for almost all of the different platforms in the enterprise world. Secondly, no installation should be required, therefore a flat jar (uber jar) which bundled all the dependencies together should be the end product.
Kotlin, 100% native java compatible is a good candidate for the above two requirements. Let’s explore some use cases.
Simple use case: Kotlin compiler
When we don’t need any java library, or the required Java module is included in one single jar file without any chained dependency, we can use the Kotlin compiler to package our prototype into a single jar file,
kotlinc -include-runtime -d myapp.jar myapp.kt
The -d
option points to the destination jar file, while -include-runtime
make the jar as a flat jar where the Kotlin runtime is included, so it can run on any JVM as,