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>( at org.jetbrains.jet.compiler.JetCoreEnvironment.<init>( at org.jetbrains.jet.compiler.CompileEnvironment.<init>( at org.jetbrains.jet.cli.KotlinCompiler.exec( at org.jetbrains.jet.cli.KotlinCompiler.exec( at org.jetbrains.jet.cli.KotlinCompiler.exec( at org.jetbrains.jet.cli.KotlinCompiler.doMain( at org.jetbrains.jet.cli.KotlinCompiler.main( Caused by: java.lang.ClassNotFoundException: org.jetbrains.asm4.ClassVisitor at$ at Method) at at java.lang.ClassLoader.loadClass( at sun.misc.Launcher$AppClassLoader.loadClass( at java.lang.ClassLoader.loadClass( ... 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 . 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 -> 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/” 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:


Good luck!