Scala on .NET via IKVM

This post will show you how to get started with writing Scala code and running it on the Mono and .NET runtimes, using a JDK re-implementation called IKVM.

So the Scala language has been gaining a lot of traction lately, mostly due to Twitter adopting it for their Kestrel messaging back-end as well as other open source projects. Another major reason why Scala is becoming increasingly relevant is the lack of velocity with which the Java community process has been incorporating various trendy language features, such as delegates, closures, and many more. There are many advantages you get when migrating from Java to Scala. So how about getting all of those and sticking close to your platform of choice, .NET?

Apparently an attempt was made to allow Scala to run over .NET, called Scala.NET. It is basically far from being production ready and only supports Scala 1.4, whereas what I'm going to show is verified to run on Scala 2.8 RC7.

1) Download the latest IKVM from SourceForge (I used
2) Download the latest Scala from scala-lang (I used 2.8 Release Candidate 7)
3) Download a recent Java JDK and JRE (I used v1.6).
4) Write a Scala application in your favorite IDE, e.g. Netbeans
(Note: Use plugin manager in Netbeans to download Scala IDE support)
A typical app looks like this:

package myscalaapp

object Main{
def main(args: Array[String]): Unit = {
println("Hello Scala on .NET!!!")

5) Build your project to create myscalaapp.jar
6) Copy myscalaapp.jar and scala-library.jar to your IKVM folder
7) Execute

ikvmc -target:exe -recurse:scala-library.jar myscalaapp.jar

8) Run myscalaapp.exe

Hello Scala on .NET!!!

Good times.

No comments:

Post a Comment