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.