A step by step process to create a lift web project. There are 2 ways to do this -
1. Download and Run Lift :
To install and run Lift, the only prerequisite is to have Java 1.5 or later installed.(Preferred 1.8)
Instructions for installing Java can be found here.
Once you have Java, the following instructions will download, build, and start a basic
Lift application.
For Windows :
• Visit http://liftweb.net/download and locate the link to the most recent ZIP version
of Lift 2.6 and save this to disk.
• Extract the contents of the ZIP file.
• Navigate in Explorer to the extracted folder, and once inside, navigate into sca‐
la_210 and then lift_basic.
• Double-click sbt.bat to run the build tool; a Terminal window should open.
• Required libraries will be downloaded automatically.
• At the SBT prompt (>), type container:start .
• You may find Windows Firewall blocking Java from running. If so, opt to “allow
access.”
• Start your browser and go to http://127.0.0.1:8080/
• When you’re done, type exit at the SBT prompt to stop your application from
running
2. Create project using SBT :
If you want to create the lift web project without using the ZIP files, then follow the below steps.
First of all, you will need to configure SBT and the Lift project yourself. We need only five small files for creating the project.
a. First, create an SBT plugin file at project/plugins.sbt (all file names are given relative to the project root directory):
This file tells SBT that you will be using the xsbt-web-plugin and chooses the correct
version based upon your version of SBT.
b. Next, create an SBT build file, build.sbt:
organization := "org.krishna.com"
name := "Lift_Using_SBT"
version := "0.1-SNAPSHOT"
scalaVersion := "2.11.0"
seq(com.github.siasia.WebPlugin.webSettings :_*)
libraryDependencies ++= {
val liftVersion = "2.6"
Seq(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile",
"org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" %"container,test",
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" %
"container,compile" artifacts Artifact("javax.servlet", "jar", "jar")
)
}
Feel free to change the various versions, though be aware that certain versions of Lift
are only built for certain versions of Scala.
Now that you have the basics of an SBT project, you can launch the sbt console. It should
load all the necessary dependencies, including the proper Scala version, and bring you
to a prompt.
c. Next, create the following file at src/main/webapp/WEB-INF/web.xml:
d. Next, create a sample index.html file at src/main/webapp/index.html for our Lift app to
load. For example:
To get the sample code, just clone the project from here
3 Cheers !!!
1. Download and Run Lift :
To install and run Lift, the only prerequisite is to have Java 1.5 or later installed.(Preferred 1.8)
Instructions for installing Java can be found here.
Once you have Java, the following instructions will download, build, and start a basic
Lift application.
For Windows :
• Visit http://liftweb.net/download and locate the link to the most recent ZIP version
of Lift 2.6 and save this to disk.
• Extract the contents of the ZIP file.
• Navigate in Explorer to the extracted folder, and once inside, navigate into sca‐
la_210 and then lift_basic.
• Double-click sbt.bat to run the build tool; a Terminal window should open.
• Required libraries will be downloaded automatically.
• At the SBT prompt (>), type container:start .
• You may find Windows Firewall blocking Java from running. If so, opt to “allow
access.”
• Start your browser and go to http://127.0.0.1:8080/
• When you’re done, type exit at the SBT prompt to stop your application from
running
2. Create project using SBT :
If you want to create the lift web project without using the ZIP files, then follow the below steps.
First of all, you will need to configure SBT and the Lift project yourself. We need only five small files for creating the project.
a. First, create an SBT plugin file at project/plugins.sbt (all file names are given relative to the project root directory):
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "0.9.0") |
version based upon your version of SBT.
b. Next, create an SBT build file, build.sbt:
organization := "org.krishna.com"
name := "Lift_Using_SBT"
version := "0.1-SNAPSHOT"
scalaVersion := "2.11.0"
seq(com.github.siasia.WebPlugin.webSettings :_*)
libraryDependencies ++= {
val liftVersion = "2.6"
Seq(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile",
"org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" %"container,test",
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" %
"container,compile" artifacts Artifact("javax.servlet", "jar", "jar")
)
}
Feel free to change the various versions, though be aware that certain versions of Lift
are only built for certain versions of Scala.
Now that you have the basics of an SBT project, you can launch the sbt console. It should
load all the necessary dependencies, including the proper Scala version, and bring you
to a prompt.
c. Next, create the following file at src/main/webapp/WEB-INF/web.xml:
<web-app><filter><filter-name>LiftFilter</filter-name><display-name>Lift Filter</display-name><description>The Filter that intercepts Lift calls</description><filter-class>net.liftweb.http.LiftFilter</filter-class></filter><filter-mapping><filter-name>LiftFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>
The web.xml file tells web containers, such as Jetty as configured by xsbt-web-plugin ,to pass all requests on to Lift.
load. For example:
<!DOCTYPE html><html><head><title>Lift using SBT</title></head><body><h1>Welcome, you now have a working Lift installation</h1></body></html>e. Finally, set up the basic Lift boot settings by creating a Boot.scala file at src/main/scala/bootstrap/liftweb/Boot.scala. The following contents will be sufficient: package bootstrap.liftwebimport net.liftweb.http.{Html5Properties, LiftRules, Req}import net.liftweb.sitemap.{Menu, SiteMap}/*** A class that's instantiated early and run. It allows the application* to modify lift's environment*/class Boot {def boot {// where to search snippetLiftRules.addToPackages("org.knoldus.com.Lift_Using_SBT")// Build SiteMapdef sitemap(): SiteMap = SiteMap(Menu.i("Home") / "index")// Use HTML5 for renderingLiftRules.htmlProperties.default.set((r: Req) =>new Html5Properties(r.userAgent))}}You have a working web lift projectTo run the application, follow below command : 3 Cheers !!!
No comments:
Post a Comment