The other day I attended a Brown Bag Lunch by Nicolas Martignole on Scala. He spoke passionately about the language, and got me interested in dusting off my Coursera notes and start playing with it again.

Scala is a powerful, solid, very expressive functional language. And since it runs on JVM, it should be possible to sneak some Scala code into Java projects.

As a first step in that direction, I tried adding a Scala Maven module inside a Java Maven project. I started with this minimalistic pom:

<project xmlns="" xmlns:xsi=""





And of course a mandatory “hello world!” application:

package com.example.scala

object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world!")

This is ready to build, package, and run:

$ mvn package
$ java -cp 'target/scala-examples-1.0-SNAPSHOT.jar;$HOME/.m2/repository/org/scala-lang/scala-library/2.10.3/scala-library-2.10.3.jar' com.example.scala.HelloWorld
Hello, world!

To get it working in Eclipse, you have to jump through a few more hoops:

  • Open **Help Install New Software…, and install the **Maven Integration for Eclipse from the update site:
  • Open **Help Eclipse Marketplace, search for “Scala”, and install **The Scala IDE for Eclipse 3.0.2
  • Import the Maven module, using **File Import… Existing Maven Projects…**

After this, now you can open HelloWorld.scala, with nice syntax highlighting, and the Run As | Scala Application context menu.

If you right-click on the project in Package Explorer, select Scala | Create Scala interpreter in scala-examples, you get a nice interpreter where you can easily test Scala expressions, for example:

Some gotchas I had along the way:

blog comments powered by Disqus