Book Image

Lift Application Development Cookbook

By : Gilberto Tadeu Garcia Jun
Book Image

Lift Application Development Cookbook

By: Gilberto Tadeu Garcia Jun

Overview of this book

Developing secure web applications is one of the most important tasks developers have to deal with. With Lift, it is easy to create solid and formidable web applications as it is the most secure web framework available today. The View-First approach and being able to handle things as purely data transformation, makes working with Lift an exciting task. "Lift Application Development Cookbook" teaches you how to build web applications using this amazing framework. The book moves gradually, starting with the basics (starting a new project, submitting a form, and so on) before covering more advanced topics such as building a REST API and integrating your application with other technologies and applications. "Lift Application Development Cookbook" takes you on a journey of creating secure web applications. Step-by-step instructions help you understand how things work and how various elements relate to each other. You'll learn different ways to process a form, build dynamic HTML pages, and create an API using REST. You'll also learn how to work with relational and NoSQL databases and how to integrate your application with other technologies as well as with third-part applications such as Gmail and Facebook. By the end of the book, you will be able to understand how Lift works and be able to build web applications using this amazing and exciting framework.
Table of Contents (15 chapters)
Lift Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a Lift application using Maven


In the previous recipe, we learned how to use SBT to create and run a Lift application. Now I will show you how to set up and run a Lift application using Maven, which is another build tool.

Getting ready

If you don't have Maven installed and configured on your computer, go to http://maven.apache.org/download.cgi, download Maven 3.1.0, and follow the installation instructions.

How to do it...

We will use a Maven archetype that will create a ready-to-use Lift application for us.

  1. Open a cmd window and run the following command:

    mvn archetype:generate ^
      -DarchetypeGroupId=net.liftweb ^
      -DarchetypeArtifactId=lift-archetype-basic_2.9.1 ^
      -DarchetypeVersion=2.5 ^
      -DarchetypeRepository=https://oss.sonatype.org/content/repositories/releases
    ^
      -DgroupId=lift.cookbook ^
      -DartifactId=chap01-mvn ^
      -Dversion=1.0
    

    After running the previous command, Maven will start to download all the required libraries to create the project.

  2. Once the download is complete, Maven will ask you to confirm some information about the project. Confirm them by typing Y and pressing return.

  3. Change the following tags in the pom.xml file:

    From:

    <scala.version>2.9.1</scala.version>

    To:

    <scala.version>2.10</scala.version>

    From:

    <artifactId>lift-mapper_2.9.1</artifactId>

    To:

    <artifactId>lift-mapper_2.10</artifactId>

    From:

    <artifactId>lift-jquery-module_2.9.1</artifactId>
    <version>2.5-2.0</version>

    To:

    <artifactId>lift-jquery-module_2.5_2.10</artifactId>
    <version>2.4</version>

    From:

    <groupId>org.scala-tools</groupId>
    <artifactId>maven-scala-plugin</artifactId>
    <version>2.15.2</version>

    To:

    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.1.5</version>

    From:

    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>6.1.26</version>

    To:

    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
  4. When you have finished editing the pom.xml file, open a cmd window, go to the folder containing the pom.xml file, and run the following command to update and compile the project:

    mvn compile
    
  5. Once Maven finishes the compilation, you will be able to start the application by running the following command:

    mvn jetty:run
    
  6. Now that you have the application up and running, you can access http://localhost:8080 in your favorite browser, and you should see a welcome page similar to the following:

How it works...

When you create a project using the Lift archetype, you get a fully working application containing everything you need to build your own application. This means that Maven will create an application with its default directory structure, a pom.xml file, with everything needed by the sample application. It will also include the jetty plugin that will allow us to run the application by running the jetty:run command.

The application created by Maven is a sample application that contains Blueprint CSS and a Mapper model. One more thing to notice is that this archetype also includes plugins for IntelliJ IDEA and Scala IDE.

See also

To learn more about Maven, please go to http://maven.apache.org/.