liveBook · Manning

JavaAppPackaging

As explained in Akka in Action, Second Edition

JavaAppPlugin is an sbt-native-packager plugin that provides packaging and deployment support for Java applications.

JavaAppPackaging is an sbt-native-packager plugin that packages a Java application with its JAR dependencies on the classpath. The project needs a class with an executable main method as its entry point. section 13.2.1

Use JavaAppPackaging with a format plugin to separate application contents from the external package:

  • JavaAppPackaging defines what is packaged and its internal structure. section 13.2.1
  • DockerPlugin turns the packaged application into a Docker image and configures its base image and exposed ports. section 13.2.1
  • JavaAppPlugin accepts deployment-time Java settings such as JAVA_OPTS for memory configuration. section 13.2.3

Packaging a clustered application

Enable JavaAppPackaging and DockerPlugin, declare a main class, select an AdoptOpenJDK 11 JRE base image, expose the required ports, and publish the image with sbt. Kubernetes can then deploy the image, while JAVA_OPTS such as -Xmx1024m configures the application container. section 15.3.2 section 13.2.3

version := "0.1.0-SNAPSHOT"                        #1
enablePlugins(JavaAppPackaging, DockerPlugin)      #2
dockerExposedPorts := Seq(8558, 2552)              #3
dockerBaseImage := "adoptopenjdk:11-jre-hotspot"   #4

Shows the minimal build.sbt settings for enabling Java application and Docker packaging, selecting ports, and choosing a base image. section 13.2.1

lazy val `betting-house` = project
    .in(file("betting-house"))
    .enablePlugins(AkkaGrpcPlugin, JavaAppPackaging, DockerPlugin)
    .settings(
      version := "0.1.1-SNAPSHOT",                                    #1
 
      Compile / mainClass := Some("example.betting.Main"),            #2
 
      dockerExposedPorts := Seq(8558, 2552, 9000, 9001,9002,9003),    #3
 
      dockerBaseImage := "adoptopenjdk:11-jre-hotspot",               #4
 
      dockerUsername := "yourusername",                               #5
 
      libraryDependencies ++= Seq(
        ...                                                           #6
      ))

Shows a complete project configuration with a main class, version, exposed cluster ports, Docker registry username, and Java 11 runtime image. section 15.3.2

How Akka in Action, Second Edition covers it

How deep it goes
Explains packaging contents, entry-point requirements, Docker parameters, publishing, and deployment options without detailing plugin internals.
Examples
Uses build.sbt settings, sbt docker:publish commands, Docker image tags, Kubernetes deployments, and JAVA_OPTS memory configuration.
What it assumes
Assumes an sbt project with a Java main method and introduces the required packaging, Docker, and deployment configuration.
What you can do after
Build it from scratch as a Java application JAR, wrap it in a Docker image, publish it, and configure its Kubernetes deployment.
How it connects
Connects Java applications with sbt-native-packager, DockerPlugin, Docker images, Kubernetes, and JavaAppPlugin deployment settings.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Akka in Action, Second Edition. The section links point to the parts of the book it draws on.