samedi 23 juillet 2011

Running Lift + Jetty 7 with SBT

Now I got SBT 0.10 running on my machine, I am going to describe in this message how to run Lift Web framework on Jetty. The basic steps are :
  • Create a new build.sbt file in the root of your project

    name := "projname" scalaVersion := "2.9.0" seq(webSettings: _*) // If using JRebel jettyScanDirs := Nil libraryDependencies ++= Seq( "net.liftweb" %% "lift-webkit" % "2.4-M1" % "compile->default", "net.liftweb" %% "lift-mapper" % "2.4-M1" % "compile->default", "net.liftweb" %% "lift-wizard" % "2.4-M1" % "compile->default") libraryDependencies ++= Seq( "junit" % "junit" % "4.5" % "test->default", "org.mortbay.jetty" % "jetty" % "6.1.22" % "jetty", "javax.servlet" % "servlet-api" % "2.5" % "provided->default", "com.h2database" % "h2" % "1.2.138", "ch.qos.logback" % "logback-classic" % "0.9.26" % "compile->default" ) Note :

    seq(webSettings: _*) requires you to import Web plugin repo.

  • Add a plugin to project/plugins/build.sbt:
    resolvers ++= Seq(
    "Web plugin repo" at "http://siasia.github.com/maven2",
    Resolver.url("Typesafe repository", new java.net.URL("http://typesafe.artifactoryonline.com/typesafe/ivy-releases/"))(Resolver.defaultIvyPatterns)
    )
    
    //Following means libraryDependencies += "com.github.siasia" %% "xsbt-web-plugin" % "0.1.0-""
    libraryDependencies <+= sbtVersion(v => "com.github.siasia" %% "xsbt-web-plugin" % ("0.1.0-"+v)
    
    
  • Run sbt
    
    $ sbt
    [info] Set current project to default-1bd591 (in build file:/home/gregory/workspace_scala/gregorydesvaux/myproject/project/plugins/)
    [info] Set current project to default-11338e (in build file:/home/gregory/workspace_scala/gregorydesvaux/myproject/)
    > jetty-run
    2011-07-23 18:08:41.225:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
    [info] jetty-6.1.22
    [info] NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet
    [info] Started SelectChannelConnector@0.0.0.0:8080
    >
    
    
    
  • Download a HelloWorld lift project
    mvn archetype:generate -U \
    -DarchetypeGroupId=net.liftweb \
    -DarchetypeArtifactId=lift-archetype-blank \
    -DarchetypeVersion=1.0 \
    -DremoteRepositories=http://scala-tools.org/repo-releases \
    -DgroupId=demo.helloworld \
    -DartifactId=helloworld \
    -Dversion=1.0-SNAPSHOT
    
    Copy paste Helloworld/src folder in your project
    
    
  • Start the Jetty server and serves this project as a web application 
    on http://localhost:8080.
    
    $ sbt [info] Set current project to default-8d78a6 (in build file:~/workspace_scala/project/plugins/) [info] Updating {file:~/workspace_scala/project/plugins/}default-8d78a6... [info] Done updating. [info] Set current project to default-53af3b (in build file:/) > jetty-r jetty-reload jetty-run > jetty-run [info] Updating {file:/home/gregory/workspace_scala/gregorydesvaux/chessgame/}default-53af3b... [info] Done updating. [info] Compiling 2 Scala sources to /home/gregory/workspace_scala/gregorydesvaux/chessgame/target/scala-2.9.0.final/classes... 2011-07-23 19:12:10.457:INFO::Logging to STDERR via org.mortbay.log.StdErrLog [info] jetty-6.1.22 [info] NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet 19:12:12.709 [main] ERROR net.liftweb.util.Props - Failed to find a properties file (but properties wereaccessed). Searched: /props/gregory.gregory.props, /props/gregory.props, /props/gregory.props, /props/default.props, /gregory.gregory.props, /gregory.props, /gregory.props, /default.props [info] Started SelectChannelConnector@0.0.0.0:8080 > 19:12:23.106 [4216250@qtp-5658067-0 - /] INFO net.liftweb.util.TimeHelpers - Service request (GET) / returned 200, took 1181 Milliseconds 19:12:23.203 [4216250@qtp-5658067-0 - /classpath/jquery.js] INFO net.liftweb.util.TimeHelpers - Servicerequest (GET) /classpath/jquery.js returned 304, took 40 Milliseconds 19:12:23.372 [4216250@qtp-5658067-0 - /ajax_request/liftAjax.js] INFO net.liftweb.util.TimeHelpers - Service request (GET) /ajax_request/liftAjax.js returned 200, took 41 Milliseconds
    Congratulations you have a Lift app running on Jetty 7!

Aucun commentaire: