3

Can I use both in my project?

Previously I had only object extending App trait, but since I started using Microkernel I need to have class extending Bootable trait.

Let's say that I have something like this:

lazy val backend = (project in file("backend"))
  .enablePlugins(AkkaAppPackaging)
  .enablePlugins(UniversalPlugin)
  .settings(
    name := "backend",
    mainClass in Compile := Some("backend.Backend"),
    libraryDependencies ++= Dependencies.backend,
    javaOptions in run ++= Seq("-Djava.library.path=./sigar"),
    fork in run := true)
  .dependsOn(api)
  .aggregate(api)

and Backend class like this:

class Backend extends Bootable {

      val system = ActorSystem("mobile-cluster")

      def startup() = {
        FactorialBackend startOn system
      }

      def shutdown() = {
        system.shutdown()
      }
    }

I cannot start app with sbt run (there is an error about missing static main method), but it works with Microkernel, when I run sbt stage and next start application using generated script it works fine.

When I'm using something like this:

object Backend extends App {

      val system = ActorSystem("application")

      FactorialBackend startOn system
    } 

I can start app with sbt "project backend" "run", but Microkernel doesn't work anymore.

What can I do with that? Should I have separate files for starting application with Microkernel and sbt or separate build configurations?

I need to have a production version of application using Microkernel and I also want to just run and debugging my application during development using sbt.

I tried to use the same class or object extending both, App and Bootable trait or configure sbt.build to have separate configuration for Microkernel and sbt run, but it didn't help.

Piotr Kozlowski
  • 899
  • 1
  • 13
  • 25

3 Answers3

0

One solution is to create another module, put there bootable class and add additional build configuration:

lazy val backend = (project in file("backend"))
  .settings(
    name := "backend",
    libraryDependencies ++= Dependencies.backend,
    javaOptions in run ++= Seq("-Djava.library.path=./sigar"),
    // this enables custom javaOptions
    fork in run := true)
  .dependsOn(api)
  .aggregate(api)

lazy val boot = (project in file("boot"))
  .enablePlugins(AkkaAppPackaging)
  .enablePlugins(UniversalPlugin)
  .settings(
    name := "boot",
    mainClass in Compile := Some("com.example.Boot"),
    libraryDependencies ++= Dependencies.backend,
    // this enables custom javaOptions
    fork in run := true)
  .dependsOn(backend)
  .aggregate(api, backend)

Right now I can run

sbt "project backend" "run"

and

sbt "project boot" "stage"
Piotr Kozlowski
  • 899
  • 1
  • 13
  • 25
  • This is a nice solution. I first though of a companion object extending your `Bootable` class with `App` and just executes the `startup` method, which is a fine solution if you don't have a lot going on in the boot section. BTW, thanks for trying my activator :) – Muki Jan 30 '15 at 13:40
0

I don't think you need 2 modules for it.

you can run the microkernel with the following command

sbt "project backend" "run-main akka.kernel.Main Backend"

integratingweb
  • 146
  • 1
  • 3
0

Perform these instructions by sbt console:

runMain akka.kernel.Main Backend
Dmitry
  • 291
  • 2
  • 6
  • 19