官术网_书友最值得收藏!

Creating a Lift application using SBT

SBT is a build tool for Scala and Java projects. The idea of using a build tool such as SBT is to make it easier to manage all of the project dependencies. Also, it helps to ensure that the application generated by the build process is always the same. This means that it doesn't matter whether the application is built on my computer or yours, the end result will be the same.

The easiest way to start with Lift and SBT is by downloading them from the official website. There, you can find a list of tar.gz and .zip files containing everything you need to start using Lift.

Getting ready

Scala, and in turn, the Lift development requires a JVM and because of this, you'll need to install Java 7 on your computer. However, you can skip this step if you already have it installed. If not then go to http://java.com and click on the Free Java Download button. Then, download and install the JDK appropriate for your OS.

How to do it...

Carry out the following steps:

  1. First of all, to install and run Lift on Windows, you will need to download the Lift 2.5 ZIP file, which is the latest stable release, from http://liftweb.net/download.
  2. After the download is complete, open Windows Explorer and extract the contents from the file.
  3. Then, go to scala_210/ift_basic, double click on the sbt.bat file to run SBT, and wait until SBT finishes downloading the required libraries. This process can take a while depending on the speed of your internet connection.

    When the download part is completed, you will get the SBT prompt that can be recognized by the > character.

  4. After getting into the SBT prompt, type the following command to start the basic Lift application:
    > container:start
    
  5. At this point, we have a running Lift application. So, open up your favorite browser and go to http://localhost:8080. Then you should see a welcome window similar to the following screenshot:
  6. To exit SBT, you just need to type the following command in the SBT prompt:
    > exit
    

How it works...

The ZIP file contains some examples of Lift applications such as a blank application that you can use to start your application from scratch. It also contains a basic Lift application that contains Blueprint CSS and ready-to-use Mapper models, which you can use as the start point when building your own application.

The lift_basic folder contains a working Lift application. This means that you have SBT and a configured, ready-to-use project in it.

When we ran SBT, it started to download all the required libraries that the application needs (these dependencies are defined in the build.sbt file). Once this step is done, we can start the application.

After downloading the required libraries, we ran the container:start command provided by the sbt-web-plugin that deploys the Lift application into an embedded Jetty server.

You can see that inside the lift_basic application, there is a folder called project which contains a file called project.sbt. In that file, you will see that it defines three plugins for SBT. The first defined plugin is the XSBT plugin. After the XSBT plugin, there is the sbt-idea plugin and the sbteclipse plugin. The former is to enable SBT to be integrated with IntelliJ IDEA, and the latter enables SBT to be integrated with Scala IDE. Another thing to notice in the plugins.sbt file is that it matches the version of SBT to select the correct version of the sbt-web-plugin.

There's more...

To install and run Lift on Linux or Mac, perform the following steps:

  1. Download the Lift 2.5 ZIP or the tar.gz file from http://liftweb.net/download.
  2. Once you've got the file, open a shell tool and expand it.
  3. Then, go to scala_210/lift_basic, and start SBT by running the following command:
    ./sbt
    
  4. You can then continue from step 4 of the How to do it… section.

See also

主站蜘蛛池模板: 德州市| 洛阳市| 衡南县| 新宁县| 五大连池市| 阳谷县| 郴州市| 新闻| 雷波县| 什邡市| 昂仁县| 黄石市| 唐河县| 富锦市| 洪泽县| 江油市| 汪清县| 额敏县| 新龙县| 义马市| 绍兴县| 吴桥县| 三门峡市| 万全县| 苏尼特左旗| 彭水| 长兴县| 金乡县| 千阳县| 子长县| 循化| 同江市| 婺源县| 湘潭县| 福清市| 奉节县| 临朐县| 沙洋县| 瓮安县| 神木县| 浦县|