A quick note how to create a SBT project with the latest release of Akka.
Create a build.sbt file:
name := "ScalaAkkaTest"
organization := "&lt;Your organisation name&gt;"
version := "0.1.0-SNAPSHOT"
scalaVersion := "2.11.2"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.3.6"
Scala offers two ways of formatting strings. This post describes both. Continue reading
I’m learning Scala at the moment. It is a wicked and very powerful language. I can recommend anyone who knows Java and is tiered of the huge amount of code that is needed to write even the most mundane functionality to give it a try. Anyway, on my quest to learn Scala I am using the book Scala in Action, which I can highly recommend. In chapter 2 a Java servlet is required. The book shows the code that is required for the servlet, but does not explain how to create a servlet. Not very complicated of course, but why create the servlet using Java when you can create a servlet using Scala? What a great exercise 🙂 So I gave it a try. This is the result. Enjoy. Continue reading
Today I was converting a servlet from a Java implementation to a Scala implementation. I needed to print out the parameters (getParameterMap) and headers (getHeaderNames). These are implemented as java.util.Map collections with the following definition.
While converting an Java servlet example to Scala I ran into a little snag when I had to convert a java.util.Map to a concatenated String in Scala. Actually, I initially couldn’t figure out how to convert java.util.Map to scala.collections.Map. It turned out to be very simple. Here is the code example I came up with and tested with Scala Worksheet in Eclipse. The example is a little more elaborate, because I also needed to convert the Map to a concatenated string of key value pairs. Continue reading
Learning Scala is fun, but at times like it can be a daunting and frustrating experience. Like learning any new language I guess. I have found using the Scala command line interpreter can help. It turns out the the Scala IDE for Eclipse also provides an interactive interpreter. To start an interactive interpreter create a Scala project and add a Scala Worksheet (File | New… | Scala Worksheet). Give the Scala Worksheet a name, for example TestScala, and start testing and learning. After typing a statement hit CTRL+S to save and the results of each statement are displayed at the end of each line. How easy is this?
Example of interactive learning with Scala Worksheet in Eclipse
I was creating a servlet using Scala and got the following error message “To compile XML syntax, the scala.xml package must be on the classpath”. It turns out that Scala-XML has been factored out into a separate library as of Scala 2.11, so it is not included in Scala projects by default. So the dependency needs to be include in the project build.sbt using the following statement:
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.2"
Note as always you should check that there isn’t a newer version available of the library. How? Google is your friend 🙂
maven org.scala-lang.modules scala-xml
This is a quick start tutorial to get going with SBT. It is meant for myself, but you are welcome to use it too 🙂
For the detailed documentation please checkout the documentation on the SBT website. Continue reading