Error compiling Scalatra project

Seriously? Unsupported major.minor version 51.0 when compiling a Scalatra project? The complete error is “Caused by: java.lang.UnsupportedClassVersionError: org/eclipse/jetty/server/Handler : Unsupported major.minor version 51.0”. After some Googling I found the following statement “You are using different JDK versions to compile and run the application”. No way, that is not possible. Continue reading

Installing Scalatra on Windows

Scalatra is a micro framework for Scala. Installation does not seem to be as straight forward as adding Scalatra to the dependencies of build.sbt. It requires a number of other tools to work: Conscript and giter8. Conscript is a tool for installing and updating Scala code. giter8, which depends on conscript, allows you to check out project templates directly from Github. It’s the recommended way to generate Scalatra project skeletons. These are quick installation instructions for Scalatra on Windows. Continue reading

sbt cannot find play-json_2.11 library

Grrrr, just cloned some of my code from Github to my laptop. I initially worked on this code on my desktop. When I tried to compile it in sbt I got the following error sbt.ResolveException: unresolved dependency: com.typesafe.play#play-json_2.11;2.3.0: not found. It had been a while since I worked on the code so I was puzzled. It turns out there are problems with the Typesafe repository. As a workaround the repository needs to be added as a resolver to the build.sbt file.

resolvers += "Typesafe Maven Repository" at "http://repo.typesafe.com/typesafe/maven-releases/"

After this it compiled nicely. Sweet. Happy coding 🙂

What happened to akka.util.duration?

In a lot of old Akka examples you will see the following statements:

import akka.util.Timeout
import akka.util.duration._
implicit val askTimeout = Timeout(1 second)

This will give error ‘object duration is not a member of package akka.util’. It turns out duration is now included in Scala standard library. To fix the error use the following import statement:

import scala.concurrent.duration._

Check out the migration guide for other pieces of Akka functionality that have moved to Scala.

Executing a method defined in a configuration file

I have a class with a method that takes a function as parameter. This function is the strategy that determines how a file is split into chunks. This is the signature of the method.

def split(r: RemoteFileInfo, append: Boolean, workDir: File, strategy: (Long) => Int = defaultStrategy): LinkedHashSet[Chunk] = {
  ...
}

There is a companion object that provides a number of predefined strategies. I wanted to make the strategy configurable by adding it to the Akka application.conf file. Continue reading