I pulled the Scalatra examples from Github and ran the Swagger example for Scalatra version 2.3. The example runs, but the API documentation is not generated completely. I was using the example as is. Continue reading
Scala
Strange Scalatra issue that halt does not work when trait JacksonJsonSupport is mixed in
I am running Scala version 2.11.1 and Scalatra version 2.3.0 and had a strange problem that plain vanilla halt does not work when the trait JacksonJsonSupport
is mixed in with my controller class. Here are two simpel code snippets to illustrate the problem. Continue reading
Auto recompile and reload a web app in SBT
In SBT it is possible to automatically recompile and reload a web app when a source file is changed by using the following command:
container:start ~ container:reload /
The first command starts the web app container the second command watches for source file changes and reloads the web app container.
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 🙂
Using the sbt-license-plugin
I wanted to add a license header to my Scala source code files. It turns out there is a neat sbt plugin called sbt-license-plugin that does just that. Getting it to work took some fiddling around, so I thought I would share it here to save someone else the time and trouble. Continue reading
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
Loading a class dynamically using the DRY principle
I needed to load a bunch of classes dynamically based on a configuration file. As I am a big fan of the Don’t Repeat Yourself (DRY) principle (who isn’t?!?!), I didn’t want to type/copy the same code but use a reusable function. Continue reading