What happend to refactoring in Scale IDE version 3.0.4?

Refactoring functionality [1] in the Scala IDE version 3.0.4 does not work. After a little bit of Googling I found the following website Scala Refactoring. It turns out this functionality is work in progress. However, the refactoring functionality is part of the latest milestone [2] of the Scale IDE. I have tried it and it works like a dream. Added bonus is the latest version of Scala IDE works with Eclipse Luna. Take it for a spin and see what you think.

[1] For example renaming all occurrences of a variable by selecting an occurrence and hitting Shift+Alt+R.

[2] Scala IDE version 4.0.0-M3.

Creating a servlet with Scala

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

Converting a java.util.Map to scala.collections.Map

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 the interactive way with Scala Worksheet in Eclipse

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

Example of interactive learning with Scala Worksheet in Eclipse

To compile XML syntax, the scala.xml package must be on the classpath

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

Happy coding!

Installing Oracle JDK 7 in Debian/Ubuntu/Mint

I am currently learning Scala and wanted to install the Scala IDE. In the process I ran into some problems that it programs would not compile correctly, which seemed to be caused by the OpenJDK 7. So I decided to remove OpenJDK 7 and install Oracle JDK 7. All the instructions I could find to do this where downloading based on manually downloading the Oracle JDK 7 and installing it interactively. As I also wanted the installation to work in a Docker container I wanted a fully automated solution. Continue reading