Scala on Lift Setup for Eclipse

2010, Mar 22  —  ...

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
  3. Other version might or might not work
  4. Install the Scala IDE for Eclipse plugin for Scala 2.7.7
  5. Instructions:
  6. Make sure you have Apache Maven installed
  7. Maven home:
  8. Maven 2.2.0 is preinstalled with Mac OS X 10.6
  9. Change to the directory where you want to setup your Lift project
  10. From the command line run:

    mvn archetype:create -U -DarchetypeGroupId=net.liftweb \
    -DarchetypeArtifactId=lift-archetype-basic \
    -DarchetypeVersion=1.1-SNAPSHOT \
    -DremoteRepositories= \
    -DgroupId=demo.helloworld -DartifactId=helloworld -Dversion=1.1-SNAPSHOT
  11. Verify it works

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

    mvn eclipse:eclipse
  14. Open Eclipse and import the project just created
  15. 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.
  16. Open the project settings
  17. Select "Java Build Path"
  18. Click the "Libraries" tab/section
  19. Click the "Add Variable..." button
  20. Click the "Configure Variables..." button
  21. Click "New..."
  22. Enter M2_REPO fr the classpath variable name and enter the location of your maven repo, possibly (~/.m2/repository)
  23. Click "OK"
  24. Modify the projects build path
  25. Open the project settings
  26. Select "Java Build Path"
  27. Click the "Source" tab/section
  28. Select all, then click "Remove"
  29. Click "Add Folder..."
  30. Check the following directories

    • src/main/scala
    • src/main/resources
    • src/test/scala
    • src/test/resources
  31. Clean the project Project > Clean...
  32. 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:

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= \
-DremoteRepositories= \
-DgroupId=helloworld -DartifactId=helloworld -Dversion=0.1-SNAPSHOT