This is a tutorial for the Lift web framework.
This is the alpha version of the tutorial, very much a work in progress and subject to change. Unless you’re involved in the development of this tutorial, you probably want the “finished” version, which can be cloned from this GitHub repository.
This tutorial shows you how to develop a basic, yet fully functional, web application with Lift. You will start with a prototype Lift application, then incrementally add new features to the prototype until the application is complete.
- You won’t get far without Git, the distributed version control system.
- You will need the Java SE 6 JDK.
- You will also need sbt, the simple build tool.
That’s it! All additional dependencies will be downloaded for you by sbt! (So yes, you’ll need an Internet connection, too.)
- You should be comfortable with HTML (specifically XHTML), and have a basic knowledge of CSS.
- Later chapters assume some familiarity with JavaScript, specifically the jQuery AJAX library.
- Lift applications are written in the Scala programming language (as is Lift itself), so prior knowledge of Scala is a must. Seriously, if you don’t know Scala already, go learn it right now. You’ll be glad you did.
- Experience with another web application framework, while not strictly necessary, will be helpful in understanding some of the concepts addressed by this tutorial.
In other words, this tutorial is not meant to be a “Web Application Development 101” course, but more of an introduction to Lift for developers familiar with ASP.NET, PHP, Rails, or one of the many Java web application frameworks.
Easy. First, install git, if you haven’t already. Second, open up a Terminal (Command Prompt in Windows), and enter
git clone git://github.com/mtye/lift-tutorial.git
at the prompt. This will create a copy of the lift-tutorial repository in the current directory. The repository contains both the tutorial and the source code for web application you’ll be building.
The tutorial content is actually self-hosted in the web application itself. If that doesn’t make sense, it may be easier to demonstrate than explain. cd
into the lift-tutorial
directory and enter
sbt jetty
at the prompt to build and run the web app.
If sbt is set up correctly, this will download many megabytes of dependencies, compile the source code, and start an instance of the Jetty web application server. If the last few lines of your terminal output look something like this:
[info] Started [email protected]:8080
[info] == jetty-run ==
[info]
[info] == jetty ==
[info] Waiting... (press any key to interrupt)
then you should be able to see the application and tutorial at http://localhost:8080. The application is at the top of the page and the tutorial content is beneath it.
If the sbt jetty
command didn’t work for you, or you can’t see the application and tutorial at http://localhost:8080, consult the troubleshooting page on the lift-tutorial wiki.
As mentioned previously, the tutorial content is embedded in the application itself. When you first start the Jetty server, you will see a completed version of the application and an explanation of how to use it. This will give you an opportunity to experiment with the application and become familiar with the features that will be developed over the course of the tutorial.
The next step is to “rewind” the tutorial (and application) to its starting point at Chapter One and restart the Jetty server. In Chapter One, the application is just a simple “Hello World” application based on the official Lift prototype application. The tutorial content in Chapter One explains the basic concepts of Lift and the features the prototype application provides “out of the box”.
Chapter Two begins the process of incrementally adding features, chapter by chapter, until the application is complete. In the spirit of agile development, each chapter endeavors to add the smallest possible useful feature to the application, hopefully keeping each chapter concise and easily grasped.
The final chapter will bring you back to where you started, with the completed application.
With Git !
Each chapter in the tutorial corresponds to a branch in the lift-tutorial repository, with each branch based upon its predecessor. Thus Chapter One is the initial branch, Chapter Two is a branch of Chapter One, and so on, with the final chapter based on all previous branches. To switch between branches, use the git checkout
command:
git checkout chapter01
to go to Chapter One (or any other numbered chapter), and
git checkout master
to return to the final chapter with the completed application. While the tutorial assumes that you’re starting at Chapters One and advancing forward one chapter at a time, there’s nothing preventing you from jumping forward or backward a few chapters if you feel like it.
Even better, all the source code is versioned in the repository, so you’re free to make changes to the application code, secure in the knowledge that you can always return to a known state with a git reset
command after you’re done experimenting. If you’re familiar with Git, you can even create your own branches!
If you’ve cloned the Git repository and started the Jetty server with sbt, you already have started! Congratulations! Navigate to localhost:8080 with your web browser and follow the instructions there.
If not, let me recap:
- Install git, if you don’t have it already.
- Download and setup sbt, if you haven’t already.
- Clone the lift-tutorial Git respository:
git clone git://github.com/mtye/lift-tutorial.git
- Make lift-tutorial your working directory:
cd lift-tutorial
- Start the Jetty web server with sbt:
sbt jetty
- When Jetty is done loading, navigate to localhost:8080 in your web brower.
That’s it! If you have any troubles, check out the troubleshooting page. Otherwise, have fun learning a little Lift!