Standalone Lagom services with Java/Maven

I’ve spent a big chunk of the day trying to build a Java Lagom service with Maven, and run it independently without using any tooling.

I would like to get to the point where I can do the following and have a running service.

mvn package
java -Dplay.server.http.port=9000 -D........other settings...... -jar service-impl/target/service-impl-1.0-SNAPSHOT.jar

This seems to be a strangely completely undocumented use case, and I’m still having trouble unpicking the ‘magic’ that the various layers of tooling do to make it work.

Among the (as far as I can see) undocumented issues I have experienced so far are:

Play ApplicationLoader

The ApplicationLoader is described extensively in Scala but for Java services it seems to be “magic”. I still don’t think I understand how play.application.loader should be set. Do I need to write a custom application loader?

Dependencies

Short of sitting comparing lists of jars one by one, it’s not clear which extra dependencies are necessary to make a service run outside of the dev tooling. Among others, I got dependency injection errors for:

  • akka.actor.ActorSystem
  • com.typesafe.config.Config
  • Lagom ServiceRegistry (after binding an alternative ServiceLocator)
  • play.Application (see above)

Service Locator registration / Play features

I don’t mind using the ConfigurationServiceLocator but the approach described in the docs of injecting the Play Environment to use isProd doesn’t work, by default at least, and results in some extremely cryptic errors using the dev server. I lost a good hour or two working out that this was the cause of a ClassCastException between Scala colon$colon$ and Seq when running mvn lagom:runAll :dizzy_face:

So far, I’ve given up and gone back to using SBT and sbt-native-packager. But I can’t believe I am the first or last person to want to do this, so it would be great if this thread could form a starting point for documenting this use case to save others the same journey :slight_smile:

Why you not want to use reactive-lib?
This recipe demonstrate how create docker image for K8S using Maven.

If you want to run service manually, you need to analyze the content of docker image (application settings, environment variables, etc) to reproduce this yourself.

The RP tooling seems like overkill for a simple use case - it’s another layer of abstraction on top of Kubernetes and another thing to debug when something goes wrong.

It also introduces all kinds of tight coupling which to my mind slightly negates the portability value of the JVM.

In any case, the documentation describes running Lagom standalone as a use case- so if that is the case then how to do that should be covered too :)