Tuesday, December 11, 2012

Scala + Eclipse + sbt

As much as I'd like to use emacs for scala, I'm wary of using packages for a fast changing language that haven't seen any recent changes. As far as I can tell, the emacs package for scala hasn't been updated since some time in 2011. And we're nearly at 2013.

So, eclipse it is.

The next problem was getting emacs to recognize and work with a scala project correctly. I like my emacs+ extension, so I haven't updated eclipse from indigo to juno. I installed the scala extension for eclipse. I installed sbt. And I set up a simple hello world application following the sbt tutorial.

I then installed sbteclipse in sbt, and generated an sbt project. The resultant project had a funny name with the source file in the wrong place. Apparently the scala ide for eclipse doesn't like source files in the package base.

To get a nicer looking project you need a build.sbt in your project. This seems to be the minimum:

name := "hello-world"

Also put a package declaration in your hello world program, and have the source file reside in the corresponding directory.

I've also found manually creating an eclipse run configuration doesn't function correctly. Eclipse isn't able to find candidate main methods automatically, as it does for Java programs. And then I found the easy way: with your main file open, click on the run command. Voila!

To find my way around I've found a simple github project to use as a guide. The language itself seems to have adequate tutorials to get started, but understanding the scala ecosystem is taking some time and effort.