3
votes

I am trying to run scalatra with sbt using container:start command but i get "assertion failed: No lifecycle class found!" message , this is the full stack trace i got with "last container:start" :

Blockquote last container:restart java.lang.AssertionError: assertion failed: No lifecycle class found! at scala.Predef$.assert(Predef.scala:179) at org.scalatra.servlet.ScalatraListener.probeForCycleClass(ScalatraListener.scala:50) at org.scalatra.servlet.ScalatraListener.configureCycleClass(ScalatraListener.scala:64) at org.scalatra.servlet.ScalatraListener.contextInitialized(ScalatraListener.scala:23) at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800) at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:446) at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:792) at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:296) at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1359) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1352) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:744) at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:497) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:125) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:107) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:154) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:125) at org.eclipse.jetty.server.Server.start(Server.java:358) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:107) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) at org.eclipse.jetty.server.Server.doStart(Server.java:325) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at com.earldouglas.xsbtwebplugin.Jetty9Runner.start(Jetty9Runner.scala:122) at com.earldouglas.xsbtwebplugin.Container$$anonfun$containerSettings$11.apply(Container.scala:77) at com.earldouglas.xsbtwebplugin.Container$$anonfun$containerSettings$11.apply(Container.scala:74) at scala.Function8$$anonfun$tupled$1.apply(Function8.scala:35) at scala.Function8$$anonfun$tupled$1.apply(Function8.scala:34) at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47) at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42) at sbt.std.Transform$$anon$4.work(System.scala:64) at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237) at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237) at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18) at sbt.Execute.work(Execute.scala:244) at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237) at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237) at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160) at sbt.CompletionService$$anon$2.call(CompletionService.scala:30) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) [error] (container:restart) java.lang.AssertionError: assertion failed: No lifecycle class found! Blockquote

This is my LifeCycle file is called :"ScalatraBootstrap.scala" and it's content is:

import org.Server.Controllers.Controller2
import org.scalatra.example.Server._
import org.scalatra.LifeCycle
import javax.servlet.ServletContext

class ScalatraBootstrap extends LifeCycle {
  implicit val swagger = new FlowSwagger
  override

  def init(context: ServletContext) {
    context.mount(new Controller1, "/*") context.mount(new Controller2, "/string1/*") context.mount(new Controller3, "/string2/*")
  }
} 
4

4 Answers

10
votes

ScalatraBootstrap.scala should be in top package without any package name.

remove any package declerations you have in the ScalatraBootstrap.scala file.

5
votes

You may put the bootstrap class in the top, nameless package or set the relevant context parameter like this:

context.setInitParameter(ScalatraListener.LifeCycleKey,
  "my.package.MyScalatraBootstrap")
1
votes

In scalatra you need to have a class extending LifeCycle. Here's an example from the docs

Note that there is also a file called Scalatra.scala in your src/main/scala directory. This is the Scalatra bootstrap config file, and it's where you should do most of your app configuration work.

The simplest version of this file, which gets generated when you make a new project using the giter8 template, looks something like this:

import org.scalatra.LifeCycle
import javax.servlet.ServletContext
import org.yourdomain.projectname._

class ScalatraBootstrap extends LifeCycle {

  override def init(context: ServletContext) {

    // mount servlets like this:
    context mount (new ArticlesServlet, "/articles/*")
  }
}
1
votes

Old question, but as I just got the same issue No lifecycle class found and the previous responses didn't solve it, here's what did:

The solution for my case was simple. I had placed the ScalatraBootstrap.scala to src/main, no errors were given by IntelliJ. The correct path is src/main/scala. This is also shown in the Scalatra project structure page, but the formatting might cause one to place it in the wrong spot. src/main/scala/ScalatraBootstrap.scala works perfectly.