Scala on Lift Setup for Eclipse

After being introduced to Scala and Lift at the SDForum panel on Emerging Languages I asked David Pollak, the lead and BDFL of the Lift web framework, if he would come to Spoke and tell us more about Lift and Scala, and he accepted. That was last Thursday and since I didn't have any free time during working hours on Friday, I spent some time over the weekend leaning a little Scala and playing around with Lift. One of the first things that I wanted to do was to get Scala and a Lift project up and running on Eclipse.To learn the Scala language I'm reading the O’Reilly book, Programming Scala by Payne and Wampler, and in that book they reference frequently new Scala features in 2.8. It turns out, however, that the current release version of Scala is 2.7.7 and the 2.8 is only in Beta 1 right now. There is a version of Lift that works on 2.8 and there are plugins for Eclipse that will work with Scala 2.8 but, for me, getting this stack running was a dead end.

I did some digging and decided to use the current release versions of Scala, Lift, Eclipse, and the Scala Eclipse plugin. After scouring the Lift discussions group, I learned two things: first, Netbeans seems to be the IDE of choice for Scala development; second, instructions on how to setup Eclipse. Listed below are instructions on how to setup a Lift project for Eclipse based on these instructions from the discussion group.

  1. Install Eclipse 3.5.2 Classic
  2. Install the Scala IDE for Eclipse plugin for Scala 2.7.7
  3. Make sure you have Apache Maven installed

  4. Change to the directory where you want to setup your Lift project

  5. From the command line run:

    mvn archetype:create -U -DarchetypeGroupId=net.liftweb \
    -DarchetypeArtifactId=lift-archetype-basic \
    -DarchetypeVersion=1.1-SNAPSHOT \
    -DremoteRepositories=http://scala-tools.org/repo-snapshots \
    -DgroupId=demo.helloworld -DartifactId=helloworld -Dversion=1.1-SNAPSHOT
    
  6. Verify it works

    mvn jetty:run
    
  7. Press Ctrl-C to stop
  8. Run the eclipse maven command

    mvn eclipse:eclipse
    
  9. Open Eclipse and import the project just created

  10. Define M2_REPO classpath var to point to your local maven repository. There might be a way to do this by directly editing the .classpath Eclipse project file.

    1. Open the project settings
    2. Select "Java Build Path"
    3. Click the "Libraries" tab/section
    4. Click the "Add Variable..." button
    5. Click the "Configure Variables..." button
    6. Click "New..."
    7. Enter M2_REPO fr the classpath variable name and enter the location of your maven repo, possibly (~/.m2/repository)
    8. Click "OK"
  11. Modify the projects build path

    1. Open the project settings
    2. Select "Java Build Path"
    3. Click the "Source" tab/section
    4. Select all, then click "Remove"
    5. Click "Add Folder..."
    6. Check the following directories
    7. src/main/scala
    8. src/main/resources
    9. src/test/scala
    10. src/test/resources
  12. Clean the project Project > Clean...

  13. Launch src/test/RunWebApp as a Scala Application to have
    jetty run inside eclipse

Update: Instructions for Lift 2.0 and Scala 2.8.0 RC6

Do get Lift up an running with Lift version 2.0 and Scala 2.8.0.RC6, follow the instructions above except with these differences:

Install the Scala IDE for Eclipse plugin for Scala 2.8.0: http://www.scala-ide.org/

Make sure that maven 2.2.1 is installed on your machine.

From the command line run:

mvn archetype:generate -U -DarchetypeGroupId=net.liftweb
-DarchetypeArtifactId=lift-archetype-blank \
-DarchetypeVersion=2.0-scala280-SNAPSHOT \
-DarchetypeRepository=http://scala-tools.org/repo-snapshots \
-DremoteRepositories=http://scala-tools.org/repo-snapshots \
-DgroupId=helloworld -DartifactId=helloworld -Dversion=0.1-SNAPSHOT