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
