Booting Lift from command line and finding templates in webapp

28 views
Skip to first unread message

Brett Grace

unread,
May 12, 2016, 9:19:40 PM5/12/16
to Lift
I occasionally want to write CLI tools (diagnostics, maintenance, reports, etc) that share code and config with my Lift app. In general it seems to work if I do something like this:

trait ManagementCommand extends App with Loggable {

 
new Boot().boot
 
val session : LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)

}

object SomeTask extends ManagementCommand {

    S
.initIfUninitted(session) {
       
SomeSystem.doStuff()
   
}
   
System.exit(0)
}

I'm using sbt-native-packager so I can run it like so:

my-project -main code.management.SomeTask

However, one of my tasks is generating an email from a template. In this case, it can't find the template because I'm not running inside a servlet container that provides a ClassLoader which looks inside the webapp directory (I know the templates are there, because if I modify the code to explicitly prepend "webapp" to the path, it works).

Is there an easy way to make this work (aside from providing a custom ClassLoader), or is there a better approach for doing offline transactions? For the most part, I just want to share configuration and be able to run database queries that expect a session.

Thank you in advance.


Brett Grace

unread,
May 13, 2016, 1:32:43 PM5/13/16
to Lift
Okay, if I have this in my build.sbt then it works, although it seems a little ugly:

import NativePackagerHelper._
enablePlugins(JavaAppPackaging)
scriptClasspath += "../webapp"
mappings in Universal ++= directory("src/main/webapp")

It copies the contents of webapp into the distribution directory, and then adds that directory to the classpath in the bash script which is automatically created by sbt-native-packager. It seems like supplying my own LiftRules.getResource is the only other viable option, unless I'm missing some bit of configuration somewhere. Other ideas welcome.


Antonio Salazar Cardozo

unread,
May 17, 2016, 10:21:16 PM5/17/16
to Lift
That sounds about right in terms of available options, yeah :/
Thanks,
Antonio

Brett Grace

unread,
May 25, 2016, 2:38:03 PM5/25/16
to Lift
Antonio,

Good to know, thank you for replying to confirm my suspicions.

Brett
Reply all
Reply to author
Forward
0 new messages