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.
- Install Eclipse 3.5.2 Classic
- http://www.eclipse.org/downloads/
- Other version might or might not work
- Install the Scala IDE for Eclipse plugin for Scala 2.7.7
- Instructions: http://www.scala-lang.org/node/94
- Make sure you have Apache Maven installed
- Maven home: http://maven.apache.org/
- Maven 2.2.0 is preinstalled with Mac OS X 10.6
- Change to the directory where you want to setup your Lift project
-
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
-
Verify it works
mvn jetty:run
- Press Ctrl-C to stop
-
Run the eclipse maven command
mvn eclipse:eclipse
- Open Eclipse and import the project just created
- 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.
- Open the project settings
- Select "Java Build Path"
- Click the "Libraries" tab/section
- Click the "Add Variable..." button
- Click the "Configure Variables..." button
- Click "New..."
- Enter M2_REPO fr the classpath variable name and enter the location of your maven repo, possibly (~/.m2/repository)
- Click "OK"
- Modify the projects build path
- Open the project settings
- Select "Java Build Path"
- Click the "Source" tab/section
- Select all, then click "Remove"
- Click "Add Folder..."
-
Check the following directories
- src/main/scala
- src/main/resources
- src/test/scala
- src/test/resources
- Clean the project Project > Clean...
- 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