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

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

主站蜘蛛池模板: 凤庆县| 房产| 镇远县| 汝阳县| 仪陇县| 静宁县| 湾仔区| 西林县| 佛坪县| 玛多县| 偏关县| 晋中市| 四子王旗| 托克托县| 肃南| 红河县| 平度市| 义乌市| 宝坻区| 萨迦县| 沂源县| 建平县| 海安县| 怀来县| 湖南省| 交口县| 米脂县| 临沂市| 沙河市| 湘阴县| 日喀则市| 巴林左旗| 项城市| 青海省| 福清市| 伊宁市| 南平市| 宜良县| 新宁县| 罗平县| 威信县|