Lift(1)Setup a Simple Project

Lift(1)Setup a Simple Project


1.1 Install the lift app
Download the latest file https://nodeload.github.com/lift/lift_25_sbt/legacy.tar.gz/master

Expand the project with command.

>tar zxvf lift-lift_25_sbt-c62bc97.tar.gz

>mv lift-lift_25_sbt-c62bc97 life_25

>cd /Users/carl/tool/lift_25/scala_29/lift_basic

>./sbt



sbt is short for simple build tool. It is the maven to java, sbt to scala.



>container:start



It will start the web container. I can visit http://localhost:8080/.

>container:stop



1.2 Begin from the book
>git clone https://github.com/dpp/simply_lift.git



2. The ubiquitous Chat app
>cd /Users/carl/work/lift/simply_lift/chat



Make eclipse available for the project first

>./sbt

using LiftProject with sbt 0.7.5 and Scala 2.7.7



I will first check that I have scala plugin already.



Find and install this plugin https://github.com/frank06/sbt-eclipse-plugin



2.1 Import the project into Eclipse
Go to the working directory

>cd /Users/carl/tool/lift_25/scala_29/lift_basic

Delete all the files and folders, only leave the src folder.



Create a new build configuration file named build.sbt. The content of this file will be as follow:

name := "lift-basic"


organization := "com.sillycat"



version := "1.0"



scalaVersion := "2.9.1"



libraryDependencies ++= {

       val liftVersion = "2.4"

       Seq(

               "net.liftweb" %% "lift-webkit" % liftVersion % "compile",

               "net.liftweb" %% "lift-mapper" % liftVersion % "compile",

               "org.mortbay.jetty" % "jetty" % "6.1.26" % "test",

               "junit" % "junit" % "4.7" % "test",

               "ch.qos.logback" % "logback-classic" % "0.9.26",

               "org.scala-tools.testing" %% "specs" % "1.6.9" % "test",

               "com.h2database" % "h2" % "1.2.147"

       )

}




Run the command to enter sbt environment

>sbt

Command update will download all needed dependencies.

>update



We will need sbteclipse plugin to generate the Eclipse project files(.project, .classpath, etc.).

Create a file in this directory

>cd ~

>cd .sbt

>mkdir plugins

>cd plugins

>vi build.sbt

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0")



This plugin will be enabled for all the projects I have.



Then I will go back to lift_basic/build.sbt

…snip…

scalaVersion := "2.9.1"


EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource

…snip…



>sbt

sbt>eclipse with-source=true



The we can import the project as usual. But still there are some red error messages on STS.



Install the plugin on normal eclipse:http://download.scala-ide.org/releases-29/stable/site/. And I will try to import the project and see. But the problem is the same.



Error Message:
object liftmodules is not a member of package net

object eclipse is not a member of package org



Solution:
Add these lines to my build.sbt

"org.eclipse.jetty" % "jetty-webapp" % "8.1.0.RC5" %   "compile",

"org.eclipse.jetty" % "jetty-webapp" % "8.1.0.RC5" %   "test",
"net.liftmodules" % "lift-jquery-module_2.9.2" % "2.5-M1-1.0" % "compile",
"org.specs2" % "specs2_2.9.2" % "1.12.1" % "test",




>sbt update


sbt>ecipse with-source=true



We can then run the lift project in Scala IDE like this>

Right click RunWebApp.scala and select Run As --> Scala Application (or Debug As --> Scala Application). And then we can visit http://localhost:8080



Error Message:
23:29:34.331 [main] ERROR n.liftweb.http.provider.HTTPProvider - Failed to Boot! Your application may not run properly

java.lang.NoSuchMethodError: net.liftweb.util.Safe$.next()J



Solution:
There is no right now.



2.2 Try to think about other IDE
>./sbt

sbt>gen-idea



Then we can use IntelliJ IDEA to import this project.

Download the tool from here.

http://www.jetbrains.com/idea/download/index.html



But this method is only working for https://github.com/lift/lift_25_sbt.git projects and samples.



Then I import the 4 projects under this directory /Users/carl/tool/lift_25/scala_29

lift_basic

lift_blank

lift_json

lift_mvc



In every project, we can use these commands.

>cd lift_basic

>./sbt

sbt>container:start

sbt>container:stop



I can run these projects via command line. And change the codes in IDEA.



I will go and study them after play framework.



References:
http://liftweb.net/

http://simply.liftweb.net/index-Part-I.html

http://simply.liftweb.net/index-Chapter-2.html#toc-Chapter-2



http://www.spenceruresk.com/2010/10/developing-with-lift-in-eclipse/

https://github.com/frank06/sbt-eclipse-plugin

http://scala-ide.org/docs/tutorials/lift24scalaide20/index.html

猜你喜欢

转载自sillycat.iteye.com/blog/1750374