Developing with Lift in Eclipse

A few weeks back, I wrote a blog entry lamenting the attitude toward IDEs in the Scala community. A few people told me that the tooling situation was better than I’d implied, so I thought I’d spend a bit of time looking at using Scala (and Lift specifically) in Eclipse. I think the situation is still a ways away from the tooling situation for Java, but it is actually quite good, and I wanted to post a quick tutorial for those interested in developing Lift in Eclipse.

Prerequisites

This post assumes that you already have Scala 2.8 final and Eclipse 3.6 on your system. For Eclipse, I recommend upping the Xmx setting if you haven’t already – I had issues when I had multiple Lift projects imported with Xmx set to 386.

Also, this tutorial is going to use Maven, not SBT. SBT may be a better build tool for Scala projects, but I’m not sure how well it works with m2eclipse – I’m going to play with that more later.

I also assume you know how to install plugins into Eclipse – I will create a more in-depth screencast for doing all of this if there is enough interest.

1. Install m2eclipse

Install m2eclipse using the following URL:

http://m2eclipse.sonatype.org/sites/m2e

If you need full instructions, you can go here:

http://m2eclipse.sonatype.org/installing-m2eclipse.html

2. Install the Scala IDE

Get the Scala IDE for Scala 2.8.0 and Eclipse Helios here:

http://download.scala-ide.org/nightly-update-helios-2.8.0.final

3. Install the m2eclipse-scala plugin

There is a configurer for m2eclipse that will setup Scala projects for you. You can install it using the directions here:

http://github.com/sonatype/m2eclipse-scala

The short version of those instructions:

1. Download the latest jar found at this url:

http://github.com/sonatype/m2eclipse-scala/downloads

2. Copy it to the dropins/ directory in your Eclipse installation

3. Restart Eclipse

4. Create a Lift project from an Archetype

Now you can create a new Lift project from the Archetype – this is effectively the same as running the mvn archetype:generate command that the Lift ‘Getting Started’ guide tells you to.

To do this, go to File > New > Other… > Maven > Maven Project

Follow the wizard until you get to the Select an Archetype screen. In the Catalog drop-down, select the Scala-Tools.org Catalog. A list of archetypes will appear below – you can filter down to just the Lift projects by typing ‘lift’ in the Filter box. Select one of the Scala 2.8/Lift 2.1 archetypes – I selected lift-archetype-basic_2.8.0. Click next and fill in the information (group id, artifact id, and version), and then click ‘Finish’.

m2eclipse will spend a few minutes setting up your project, downloading sources, and configuring it in Eclipse.

5. Import an existing Lift project (optional)

If you already have a Maven-based Lift project, you can import it. Just select File > Import.. > Maven > Existing Maven Projects and then follow the wizard to import your project. It will configure everything for you.

6. What you can do

So, now that you have a Maven-based Lift project in Eclipse, what can you do?

– Code complete, syntax highlighting, and real-time compiler errors are available

– Code navigation works quite well – you can CMD/Control + click a class or method to go right to it. Cmd + O will let you navigate the methods and fields in the current class.

– m2eclipse will download sources for you automatically – this is one of my favorite features. If you navigate to a class in the Scala API or Lift itself, you’ll see a rough decompiled view of the class for a second while m2eclips grabs the sources, then it will refresh with the actual source code. This is a really handy feature! It will also download scaladocs for you.

– You can setup an m2eclipse command to run Jetty within the IDE. Right-click on the web project and select ‘Run as…’ > Maven build… You’ll be presented with a screen for creating a new maven runtime configuration. In the Goals box, add jetty:run, then click ‘Run’. This configuration will be saved, so you can run your project in Jetty anytime you want by using the Run button in the menu bar. You can also do this for the mvn scala:cc command if you want.

7. Final thoughts / Feedback

I think the tooling situation for Scala and Lift is pretty good – much better than when I was doing a lot of Lift work last year. A lot of credit goes to Miles Sabin, David Bernard, and others who have done a lot of work to make this possible.

If this post was helpful, please let me know. I’m also interested to know if people are interested in more in this area, specifically:

1) A screencast showing how to do all of this, and what other features are available when working with Scala/Lift projects in Eclipse.

2) A single Eclipse feature that can tie all of the above features together into one easy-to-install package, along with setting up the m2eclipse Run As.. commands automatically for you.

If either of these interest you, or you have any other ideas, please let me know. You can either leave a comment on this post or email me directly (suresk@gmail.com). You may also follow me on Twitter – @suresk.

Leave a comment ?

12 Comments.

  1. I found it helpful.

    I’d love to see a lift example using the Google appengine eclipse plugin.

  2. Great Post! This was exactly what I was looking for. Thank you very much.

    I just had one problem, when following your instructions. Starting jetty:run, i got the message “No plugin found for prefix ‘jetty'”. This was because m2eclipse used a embedded maven 3.0 installation. After setting the maven installation (window -> preferences -> maven -> installations) to my local maven 2.0 installation, everything worked fine.

  3. @atomi

    I probably won’t be doing a Lift + GAE plugin tutorial or anything. I don’t use GAE at all and I don’t think it fits particularly well with Lift. Perhaps someone who uses GAE and Lift can figure something out?

  4. @Michael

    Hmm.. That’s a little odd – I used the embedded Maven 3 and it worked fine. I’ll have to try it out in a few different scenarios to see if there is a reason it didn’t work for you.

  5. great post! everything worked right away, this should be in the lift wiki somewhere…

  6. * Alternative to calling jetty:run (with lift project) : the Run As/Debug As > Scala Application on the src/test/scala/RunWebApp.scala file (it also works with JRebel plugin)

    * I don’t use scala:cc under eclipse but the incremental + eclipse builder (run on save and do the same as scala:cc)

  7. This was a definite help. I was trying to get Scala/Lift working through Eclipse for a little while now. Being new to Maven, Scala, and Lift did not help any. I think the m2eclipse-scala plugin was the missing piece. The little information on jetty:run was helpful as well. Thanks! I will be sure to send people here for help with this.

  8. Scala (fortgesetzt) | Daniel's Blog - pingback on February 25, 2011 at 9:12 am
  9. Definitely a great help.
    Especially since I don’t care for all the SBT stuff that this book uses
    http://stable.simply.liftweb.net/

    Thanks, I appreciate this.

  10. Great work, I spent few hour fixing lift envirement before I find this post. please if you can explain how we can do again this task using sbt
    Thanks

  11. Just want to say thank you for this tutorial. It helped me a lot. I would just add that you can set up another maven task similar to “jetty:run” called “war:war” that will package up the project in a war file.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="">

Trackbacks and Pingbacks: