I'm attempting to create 'from scratch' a Lift web application and running into some difficulty. I started with xsbt-web-plugin version 2.1 , and managed to get it working with a simple Jetty servlet. Then I tried to integrate information from the Lift Cookbook .
This is my build.sbt
:
organization := "ford.nathaniel"
name := "Lift From Scratch"
version := "0.1-SNAPSHOT"
scalaVersion := "2.11.7"
libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided"
enablePlugins(JettyPlugin)
libraryDependencies ++= {
val liftVersion = "3.0-M8"
Seq(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile",
"org.eclipse.jetty" % "jetty-webapp" % "9.2.1.v20140609" % "container, test",
"org.eclipse.jetty" % "jetty-plus" % "9.2.1.v20140609" % "container, compile"
)
}
I have a (one line) project/plugins.sbt
:
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "2.1.0")
I lifted the Boot.scala
file directly from the above-linked Cookbook and placed it in src/main/scala/bootstrap
, and similarly src/main/webapp/WEB-INF/web.xml
. I can run sbt
from the command line, and it loads cleanly, but when I try container:start
...
> container:start
[info] starting server ...
[success] Total time: 0 s, completed Mar 3, 2016 9:52:25 PM
Error: Could not find or load main class
>
I am unclear on how sbt
is meant to find Lift's main class. I looked through a lot of older versions of sbt
configuration, which differ because earlier versions use earlier versions of the xsbt plugin. (Specifically, you see things like seq(webSettings :_*)
- what does that even do?) I pulled recent versions of jetty-webapp
and jetty-plus
, so I don't think that's the problem. On the other hand, none of those configurations make clear how Lift figures out where Boot.scala
is, and in turn I'm not sure how to write the configuration such that it knows how to bootstrap the framework.
One main difference between the two sources is that the new Jetty README configures the servlet like this :
libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided"
enablePlugins(JettyPlugin)
containerLibs in Jetty := Seq("org.eclipse.jetty" % "jetty-runner" % "9.2.1.v20140609" intransitive())
containerMain in Jetty := "org.eclipse.jetty.runner.Runner"
This seems to configure a SettingKey on the Jetty plugin, and point to the Jetty runner to kick off the servlet. However, given that I'm not running through a standard servlet, but through a filter configured to point to the Lift app in web.xml
, this seemed like something I should remove.
Clearly I'm misunderstanding something. How do I diagnose why the xsbt-web-plugin
is not picking up the Lift framework? It seems like either there is configuration-by-convention I can't find or I need to do something special with Jetty to point to the web.xml
filter. Can anyone help clarify how to diagnose this, or elucidate how the two libraries should work together?
The following build.sbt
ended up working for me when executed as jetty:start
(rather than container:start
). It appears that net.liftweb
needs to be included as a libraryDependency
rather than in the containerLibs
, and that the Jetty plugin manages the container. I don't understand particularly, though, what the difference is or how to diagnose this in the future (ended up just trying a lot of different things).
Notably, though, the Boot.scala
class of Lift is picked up automagically if the web.xml
file is set up to use a Lift filter.
organization := "ford.nathaniel"
name := "Lift From Scratch"
version := "0.1-SNAPSHOT"
scalaVersion := "2.11.7"
libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided"
//logLevel := Level.Debug
enablePlugins(JettyPlugin)
libraryDependencies ++= {
val liftVersion = "3.0-M8"
Seq(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile"
)
}
containerLibs in Jetty := {
val liftVersion = "3.0-M8"
Seq(
"org.eclipse.jetty" % "jetty-webapp" % "9.2.1.v20140609",
"org.eclipse.jetty" % "jetty-plus" % "9.2.1.v20140609",
"org.eclipse.jetty" % "jetty-runner" % "9.2.1.v20140609" intransitive()
)
}
containerMain in Jetty := "org.eclipse.jetty.runner.Runner"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.