Metawerx Java Hosting Small Logo

Installing Lift with Scala on Tomcat

Lift is a popular web application framework for using Scala on the server. It is probably best known as the platform used by FourSquare. Scala has also become more well known since April 2009 when Twitter announced they had switched large portions of their backend over from Ruby to Scala and intended to convert the rest.

This is a short tutorial on installing one of the sample applications from Lift 2.4 / Scala 2.9 onto Tomcat and TomEE.

For this tutorial, we deployed successfully to the following platforms, using standard Metawerx Java Hosting accounts:

  • Tomcat 7.0.27, JDK1.6u31
  • TomEE 1.0.0-beta-3 WebProfile and Plus editions, JDK1.6u31

Introduction to Lift/Scala applications

Lift/Scala applications install easily on any standard Tomcat/TomEE VM. The application is built locally and the web application is generated automatically by the build scripts, ready to WAR up and deploy. Therefore the installation is actually very simple.

Lift is built on Scala, a hybrid functional OO language that compiles code into Java bytecode. Scala code can call any Java code and make use of all Java classes.

Lift code is as clean and brief as Rails, but performs at least 6 times faster and is multithreaded. Scala is also strongly typed so the compiler catches type errors.

Other benefits of a Lift application include:

  • Resistant to common vulnerabilities including many of the OWASP Top 10
  • Fast to build, concise and easy to maintain
  • Apps scale in the real world to handle insane traffic levels
  • Simple Ajax and Comet support

Getting Started

  • First, download Lift from http://liftweb.net/download
  • Unzip it into a folder, and browse to one of the sample applications. We'll assume you chose lift_basic.
  • Execute the following command to download all the required jars and build the Lift web application:
sbt update ~jetty-run
  • When the build completes, Jetty will start automatically and the following text will be displayed:
1. Waiting for source changes... (press enter to interrupt)

Test Locally

  • Browse to the newly started Jetty instance and play with the application locally on http://127.0.0.1:8080/

Deploy to Tomcat

  • When you are happy with your new Scala/Lift application (in this case the sample application), deploy it to your live JVM
  • Go to the new target\scala_2.9.0-1 folder and you will see a folder called webapp
  • Turn this into a WAR file called lift_basic.war
  • Command-line example:
cd lift-lift_24_sbt-f911f30\scala_29\lift_basic\target\scala_2.9.0-1\webapp
jar cvf lift_basic.war .
  • The resulting WAR file will be around 22mb. Deploy this to your metawerx hosting account, and your new scala app will appear online. If you called the WAR file lift_basic.war, it will appear as http://yoursite/lift_basic

Notes on the lift_basic sample application

  • The forgotten-password feature will not send email until you configure an appropriate mail server, or have an SMTP server on localhost:25
  • The sample application uses a built-in database, find out more about how it works from the Lift documentation

Easy! Now go back and try the other samples or start developing your new Scala/Lift app!

- Neale Rudd, 14-Apr-2012

See Also

navigation
metawerx specific
search
Share
tools
help

referring pages

Share