Scala, SBT and eclipse – First steps!

This is more a documentation to myself. If it helps anyone else along the way, that would be great too.

Scala is a programming language that has been around for a while, but is newer than Java. It has strong links to Java: Scala code runs in the JVM, Java libraries can be seamlessly used. The main argument for Scala seems to be the fact, that it facilitates usage of both object-oriented and functional programming paradigms. All reasons why it was next on my list of programming languages to try out. So here is what I did:

To start with, I purchased a copy of the book “Scala for the Impatient” by Cay Horstman for its unbelievably promising title. I started reading and got bored just doing that after three pages – needed some hands-on element on the side ;) . Decided I needed to get it up and running first.

Installing Scala on my ubuntu is easy enough as it is in the packaging system.

sudo apt-get install scala

Typing in scala on console will already give you the Scala interpreter. I typed 21*2, saw 42 and was happy for the moment.

Next up was an IDE. I decided to use the Scala-flavoured Eclipse for a start. I managed to create a new Scala project and an object containing a “hello world” as you can find in many tutorials on the web. Fixing a little version mixup on my side (I told the project to use Java 8, but only had Java 7 installed…), I saw my “hello world”, and hey, happy again.

Next step was a build tool, I didn’t feel like starting programming without one. Maven seems to be an option for Scala, but since I have already used that previously, I decided to go for sbt, which many Scala programmers seem to use. The repositories containing it could be added to my computer. Documentation on the SBT project website is a treat!

With maven and the eclipse maven plugin, one could simply use the “Create a new maven project” in eclipse and have all folders and files neatly set up. How could one do this with sbt? I searched the eclipse marketplace for the often cited sbteclipse plugin, got unhappy because I didn’t find it. Reading properly helped: It’s not an eclipse plugin, but a plugin for sbt, setting up the project structure on command line. Ah well. Setting it up is not just clicking buttons, but manually editing some sbt plugin file. These links helped me along the way:

SBTeclipse github project
Stackoverflow step-by-step

I now have a hello world project running from command line with “sbt run”, from Eclipse using “Run as scala application” and with scalac compiling the class in question. Plus, the folder structure looks nice and like something I am used to.

Instagram: And, in the middle of tonight’s madness, a couple having a Picknick literally between the lines. #nolegida

Instagram: And, in the middle of tonight's madness, a couple having a Picknick literally between the lines. #nolegida
Posted by Instagrate to WordPress

Instagram: #sunrise #yoga #barceloneta

Instagram: #sunrise #yoga #barceloneta
Posted by Instagrate to WordPress

Instagram: #leipzig #karli #sunset

Instagram: #leipzig #karli #sunset
Posted by Instagrate to WordPress

Instagram: #strawberries #balconyharvest

Instagram: #strawberries #balconyharvest
Posted by Instagrate to WordPress