How to install the Scala Lift web framework

Installing the Liftweb framework for Scala turned out to be so easy it hardly merits a note-to-self – even less so a blog post. Yet, it took me a while to figure it out. If you are a Scala/Lift novice like me I hope that this quick post helps you get started. Here’s how to setup Lift on Mac, Windows or Linux. 

You don’t need to have Scala installed for this to work.

  • Install JRE 1.6+.
  • Download the Scala Build Tool V 0.7.7 sbt and save it to some directory.
  • Create a script/batch file in the same directory to wrap sbt as shown under notes further below.
  • Optionally add the script’s directory to your OS’ search path.
  • On Linux, don’t forget to assign exec permission to the script.
  • Create a project directory for your lift app somewhere and cd into it.
  • Invoke the sbt script from within your project directory. If you didn’t add sbt to your OS’ search path you have to give its absolute or relative path.
  • When prompted, answer y to create a new project.
  • Enter a project name such as HelloLift.
  • Enter your org name such as com.yourdomain.hello.
  • Enter 2.8.1 as scala version.
  • For everything else accept the defaults.
  • Wait for dependencies, which include a Scala version for sbt other than 2.8.1, to download. If you need to access the net via a proxy please refer to the notes at the end of this post.
  • At the sbt shell type *lift is org.lifty lifty 1.6.1 to install the lifty plugin – wait a little.
  • Issue lift create project-blank
  • Accept defaults except for the lift version where you need to specify 2.3 (and not the default value of 2.3-RC3).
  • Issue reload for sbt to update your project’s config.
  • Issue update to fetch dependencies including lift.
  • Type jetty to launch the app.
  • Visit http://localhost:8080 to see the Liftweb scaffolding app.

Coming from Python and web2py, a Python MVC framework that’s easy to install and get started with, this is comparatively cumbersome but I am interested in Lift’s “view-first” approach and keen to apply Scala to some projects.

Notes

Unix script

java -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=1024m -Xmx2048M -Xss4M -jar `dirname $0`/sbt-launch-0.7.7.jar "$@"

Windows batch file

set SCRIPT_DIR=%~dp0
java -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=1024m -Xmx2048M -Xss4M -jar "%SCRIPT_DIR%sbt-launch-0.7.7.jar" %*

If you get memory related errors try to reduce the Xmx and MaxPermSize parameters.

To use sbt through a proxy add the following parameters. You can omit username and password if your proxy does not require authentication.

-Dhttp.proxyHost=myproxy
-Dhttp.proxyPort=8080
-Dhttp.proxyUser=username
-Dhttp.proxyPassword=mypassword

To instruct Jetty to listen on a port other than 8080, you can add
override def jettyPort = 8081 to
project/build/Project.scala.

Finally, to shutdown jetty type jetty-stop in the sbt shell.

That’s it. Comments and corrections are very welcome.

Advertisements
This entry was posted in Lift, Scala. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s