First time with Kotlin


#1

Hi All,
This is my first time here.I have just started learning Kotlin and following the tutorial here http://kotlinlang.org/docs/tutorials/command-line.html.I 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(CompileEnvironmentUtil.java:110)
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(CLICompiler.java:107)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51)
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(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jetbrains.kotlin.preloading.Preloader.run(Preloader.java:81)
at org.jetbrains.kotlin.preloading.Preloader.main(Preloader.java:43)
Caused by: java.io.FileNotFoundException: HelloWorld.jar (Permission denied)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.(FileOutputStream.java:213)
at java.io.FileOutputStream.(FileOutputStream.java:162)
at org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentUtil.

Could somebody please help solving this?
Thanks


#2

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

You can find the documentation here:

http://kotlinlang.org/docs/reference/using-gradle.html

and the examples at the bottom.

Good luck.


#3

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?


#4

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.


#5

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.


#6

@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 https://try.kotlinlang.org/ …it works but sooner or later I’ll have to start using the command line.


#7

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.


#8

@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.


#9

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.