Trying to run kotlin scripts/files from command line

I'm trying to figure out an easy way to run Kotlin scripts either from the command line to play around with Kotlin.  I tried two different avenues, first I tried aztec which has azs to run scripts, so I installed it, but when I try to run a script I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jetbrains/asm4/ClassVisitor at com.intellij.core.JavaCoreEnvironment.<init>(JavaCoreEnvironment.java:70) at org.jetbrains.jet.compiler.JetCoreEnvironment.<init>(JetCoreEnvironment.java:47) at org.jetbrains.jet.compiler.CompileEnvironment.<init>(CompileEnvironment.java:88) at org.jetbrains.jet.cli.KotlinCompiler.exec(KotlinCompiler.java:111) at org.jetbrains.jet.cli.KotlinCompiler.exec(KotlinCompiler.java:81) at org.jetbrains.jet.cli.KotlinCompiler.exec(KotlinCompiler.java:73) at org.jetbrains.jet.cli.KotlinCompiler.doMain(KotlinCompiler.java:61) at org.jetbrains.jet.cli.KotlinCompiler.main(KotlinCompiler.java:53) Caused by: java.lang.ClassNotFoundException: org.jetbrains.asm4.ClassVisitor at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 8 more

So then I tried to kotlin-script, which says it needs kotlinc in my path, and I have no idea where to find kotlinc.  Again, no luck!

Part of my motivation is that my main project I work on all day doesn’t work with IntelliJ 11.1, so I have to switch between IntelliJ if I want to play around with Kotlin.  (I also tried the TextMate bundle, the syntax highlighting is cool, but again running a file doesn’t work).

I’ve also just tried the “kotlin” script in the kotlin project bin directory, but when I try that it says “Idea root not found”.  So if anyone has any other good ideas on running kotlin files/scripts outside of IntelliJ please share with me :slight_smile:

See http://devnet.jetbrains.net/thread/435363 . I tried to do different thing but exception looks the same. You need libraries from IDEA's core/*jar to run compiler such as asm4-all.jar

Are you sure that you need run Kotlin files from command line? Running Kotlin in scripting mode is not well-supported yet. Now, for better Kotlin experience I would recommend you either Kotlin Web Demo or IntelliJ IDEA plugin (see below). In both cases you can have syntax and error highlighting while you edit, completion and other cool stuff. But I'm sure you know it as it is.

Kotlin compiler (a.k.a. kotlinc) can be downloaded from our build server (go to Artifacts -> kotlin-0.1-xxxx.zip). To run kotlinc manually, invoke the following commands (you’ll have to have all your Kotlin sources in separate “src” folder):

kotlinc\bin\kotlinc -src src -output output
java -classpath "kotlinc\lib\kotlin-runtime.jar;output" namespace

If you want, you still can try to run third-party Kotlin script runner that you mentioned (kotlin-script).

If you want to use IDEA, but you have to switch between different versions of it, I can recommend you a way to run different versions of IDEA simultaneously. You’ll have to modify “bin/idea.properties” file in your IntelliJ IDEA 11.1 installation, uncommenting and changing lines with “idea.config.path” and “idea.system.path” properties and making them point to some dedicated directories. For instance, like this:

idea.config.path=${user.home}/.IntelliJIdea-for-kotlin/config
idea.system.path=${user.home}/.IntelliJIdea-for-kotlin/system

Good luck!