Create a LiftWeb project with Simple Build Tool

If you are like me an eternal beginner on the Lift Web Framework, after starting a few attempts you probably think that perhaps maven lift archetypes are sometimes really slow process to start a liftweb project, and also that you need something more intuitive as Rails or Grails. Most of the time, when I am using maven, I need to look on the documentation again and again. So I have decided that I would like to use other option such as the Simple Build Tool.

First, we are going to install sbt. I have already made a small tutorial of how to install sbt for Mac OS X Leopard users, which is located here

Once the SBT tool has finally been installed, we proceed to create the lift project structure, there are 2 ways to create a Lift Project, the first one to create a new project by the traditional means using maven:

  mvn archetype:generate \
           -DarchetypeGroupId=net.liftweb \
           -DarchetypeArtifactId=lift-archetype-basic_2.8.0 \
           -DarchetypeVersion=2.1                           \
           -DarchetypeRepository=http://scala-tools.org/repo-snapshots \
           -DremoteRepositories=http://scala-tools.org/repo-snapshots \
           -DgroupId=org.activoricordi.cloudconsole \
           -DartifactId=dbcloudconsole \
           -Dversion=1.0

Then use sbt to manage the rest. We later build the sbt project. However, this way of working is precisely what I want to avoid.

The other option is to use git and download the lift-sbt-prototype from the LiftWeb Prototype Site. If you have not downloaded git, I would suggest two options or either find at Google a good tutorial of how to do it or the other option is to wait for new tutorial where we explain how we install it in Eclipse.

We clone the project repository using the following command:

git clone git://github.com/lift/lift_sbt_prototype.git

But there is a better option, which is using Lifty. Lifty is a SBT processor for generating files associated with the Lift framework. It is a open source project created by Mads Hartmann, which is based on a sbt framework called Lifty engine, which we will describe another day.

Lifty site

Lifty site

mkdir lifty_test
cd lifty_test
sbt

Once we enter the sbt command the following message will appear:

Project does not exist, create new project? (y/N) : y

SBT Project Creation Line


If we select the option Y and we then to enter commands to fill the parameters appear:

  • Name:liftytest
  • Organization:org.lifty
  • Version [1.0]:1
  • Scala version [2.7.7]: 2.8.0
  • sbt version [0.7.4]: 0.7.4
  • Here we can see an screenshot of the process:

    sbt_project_creation_process

    Screenshot from sbt project creation process


    This means that we have created a normal scala project, where we have filled the necessary fields
    We then enter the following command at the sbt prompt which are located on this page: http://lifty.github.com/Lifty/:

    *lifty is org.lifty lifty 1.3
    

    This command download the lifty processor.

    To test it, we are going to enter the following command.

    lifty help
    

    The lifty processor is quite simple, supporting the following commands:

    help: This will list all of the available commands
    templates: This will list all of the available templates
    create: This will attempt to create on of the templates

    lifty create project
    

    This command creates all the structure needed to execute the project. Even it creates the command.

    import sbt._
     
    class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) {
      val mavenLocal = "Local Maven Repository" at
      "file://"+Path.userHome+"/.m2/repository"
     
       val scalatoolsSnapshot = "Scala Tools Snapshot" at
      "http://scala-tools.org/repo-snapshots/"
     
      val scalatoolsRelease = "Scala Tools Snapshot" at
      "http://scala-tools.org/repo-releases/"
     
      val liftVersion = "2.1-SNAPSHOT"
     
      override def libraryDependencies = Set(
        "net.liftweb" %% "lift-webkit" % liftVersion % "compile->default",
        "net.liftweb" %% "lift-testkit" % liftVersion % "compile->default",
        "net.liftweb" %% "lift-wizard" % liftVersion % "compile->default",
        "net.liftweb" %% "lift-mapper" % liftVersion % "compile->default",
        "com.h2database" % "h2" % "1.2.138",
        "org.mortbay.jetty" % "jetty" % "6.1.22" % "test->default",
        "junit" % "junit" % "4.5" % "test->default",
        "org.scala-tools.testing" % "specs" % "1.6.1" % "test->default"
      ) ++ super.libraryDependencies
    }

    As a tip, I would recommend adding are going to add the following dependencies which I consider very valuable.

    "net.liftweb" %% "lift-widgets" % liftVersion % "compile->default",

    Once we add it we have to save the file and use the sbt reload command again.
    To summarize:
    a) We create the folder with the name of the project we want to create
    b) We access to the folder and we then use the sbt command
    c) Instead of filling it

Install the Simple Build Tool for LiftWeb Framework

Install the Simple Build Tool (SBT) for LiftWeb Framework

Best way to install SBT for Mac OS X is described on the following tutorial called Getting Started with Scala using SBT.
However, in this case since I do not have wget installed, we have downloaded the sbt-launcher.jar file from the official Simple Build Tool and place it on our Downloads folder. Using the following commands, we can install the sbt launcher and make it accessible from the command tools :

cd ~
sudo mv ~/Downloads/sbt-launch-0.7.4.jar /usr/local/bin/sbt-launcher.jar
echo "java -Xmx512M -jar /usr/local/bin/sbt-launcher.jar \"\$@\"" | sudo tee /usr/local/bin/sbt
sudo chmod +x /usr/local/bin/sbt

Thank’s to Chris Moos script, the SBT jar is installed and it creates a script called sbt that will allow us to run the sbt jar. To test it just type sbt and press enter, and you now have access to SBT.

Create a Lift Project with Maven

Install Lift 2.1 in MacOSX Leopard > (4) Create a Lift Project with Maven:

The Apache Maven has become a standard, a standard that is already installed in Mac OS X Leopard by default, and there is no need to installed again. It is also possible to update it.

Once the maven is installed, we can use it to create a Lift Project, you could start the mvn command, and create a project with the following structure.

mvn archetype:generate \
 -DarchetypeGroupId=net.liftweb \
 -DarchetypeArtifactId=lift-archetype-basic_2.8.0 \
 -DarchetypeVersion=2.1 \
 -DarchetypeRepository=http://scala-tools.org/repo-releases \
 -DremoteRepositories=http://scala-tools.org/repo-releases \
 -DgroupId=org.activoricordi.app \
 -DartifactId=lift_app_test \
 -Dversion=1.0

We are going to analyze each of the terms on this archetype:

  • archetype:create -U: It indicates the type of archetype we are going to use, there could be others which we will use to build the application or deployed
  • -DarchetypeArtifactId can have one of the three values
    • - lift-archetype-blank: To create a blank project without any database or ORM.
    • - lift-archetype-basic:To create a liftweb project with ORM and derby database, it is good for prototyping a project and help to start with beginners
    • - lift-archetype-jpa-basic To create a liftweb project with ORM and jpa database

    We modify the following parameters to adjust it to our project:

    -DgroupId=org.activoricordi.app \
     -DartifactId=lift_app_test \
     -Dversion=1.0

    Once the execution of the Maven is completed, we execute the following commands:

Install Lift 2.1 in MacOSX Leopard (I) – Download the Scala Language

1) Download the Scala Language:

We download the Scala language file from the scala-lang site. We are going to install it following the instructions given by the following sites Installing Scala on Mac OS X Leopard and How to Install Scala on Mac. I have done a quick summary of the great tips:

  • We go the official Scala Web Site, http://www.scala-lang.org/downloads.
  • Download the installer for your environment and follow the instructions on the downloads page.
  • I download the scala-2.8.0.final.tgz, I extract it in the Downloads folder.