First time with Kotlin


Hi All,
This is my first time here.I have just started learning Kotlin and following the tutorial here am working on Ubuntu 16.04 LTS and can see that JAVA_HOME AND KOTLIN_HOME are set.But when I try to compile and run with
kotlinc hello.kt -include-runtime -d hello.jar I am getting an error…

exception: org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentException: Invalid jar path HelloWorld.jar
at org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentUtil.writeToJar(
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.writeOutput(KotlinToJVMBytecodeCompiler.kt:89)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileBunchOfSources(KotlinToJVMBytecodeCompiler.kt:252)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:207)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:61)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:70)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:36)
at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit(CLITool.kt:157)
at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMain(CLITool.kt:148)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion.main(K2JVMCompiler.kt:331)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.kt)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.jetbrains.kotlin.preloading.Preloader.main(
Caused by: HelloWorld.jar (Permission denied)
at Method)
at org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentUtil.

Could somebody please help solving this?


Apart your specific issue, I strongly suggest you to use a build tool, like Gradle.

You can find the documentation here:

and the examples at the bottom.

Good luck.


Thanks @fvasco . I am not building a project but the most basic Hello World in Kotlin. Do you still think I need to use Gradle?


If you want to continue using kotlin in future, you do need to study build system, because you will definitely need it (you won’t regret it since gradle is indeed great tool). It is much better to spend few hours investigating it now then few weeks when you will really need something complicated.
Also, for JVM ecosystem tooling is a very important part of the program.


I fully agree with @darksnake,
however if you want type some code for a first approach, then I suggest you to use:

I started here, it is ready and simple to use, moreover it contains a lot of useful excercises for a begginner.


@darksnake @fvasco I fully agree with you guys about learning Gradle.I have a passing familiarity with it i Grails; i should certainly look deeper into it.But as newcomer to Kotlin I have to understand the environment from the command line-how everything works together.@favsco I’ve tried …it works but sooner or later I’ll have to start using the command line.


I’ve worked in JVM ecosystem for almost ten years and I almost never used java compiler form the command line. Of course, both gradle and maven are used from command line. Particularly, gradle have a very convenient command line tools. Currently, you can install it quite easily via sdkman and never leave your favorite terminal at all.


@darksnake I’ll definitely have to use a build tool to create a full blown application.But in this case I am getting an exception.I don’t think it’s anything to do with a build tool.The build tool might help me get rid of the exception;but I want to know the cause of the exception in the first place.


After looking through your stacktrace, the source of the error is rather obvious:

For some reason compiler does not have permissions to write to your output directory. I do not know the reason behind it, but you can try to solve it by manipulating directory permissions.