I am new to java playframework. I was asked to generate a hello world app in java playframework and dockerize it.
Requirements
java 17
playframework: 3.0.3
I installed java 17 on my system and downloaded sbt then entered this command to generate a boilerplate
<code>sbt new playframework/play-java-seed.g8
</code>
<code>sbt new playframework/play-java-seed.g8
</code>
sbt new playframework/play-java-seed.g8
Dockerfile
<code># Use an official OpenJDK runtime as a parent image for the build stage
FROM openjdk:11-jdk-slim AS builder
# Set the working directory in the container
WORKDIR /app
# Install necessary tools and sbt
RUN apt-get update && apt-get install -y curl unzip &&
curl -L -o /tmp/sbt.tgz https://github.com/sbt/sbt/releases/download/v1.4.7/sbt-1.4.7.tgz &&
mkdir -p /usr/local/bin/sbt &&
tar -xzf /tmp/sbt.tgz -C /usr/local/bin/sbt --strip-components=1 &&
ln -s /usr/local/bin/sbt/bin/sbt /usr/bin/sbt &&
rm /tmp/sbt.tgz
# Copy the application code to the container
COPY . /app
# Build the application
RUN sbt dist
# Use an official OpenJDK runtime as a parent image for the runtime stage
FROM openjdk:11-jre-slim
# Set the working directory in the container
WORKDIR /app
# Copy the distribution zip file from the builder stage
COPY --from=builder /app/target/universal/*.zip /app/
# Extract the distribution zip file
RUN apt-get update && apt-get install -y unzip &&
unzip /app/*.zip &&
rm /app/*.zip
# Expose the port that the Play app runs on
EXPOSE 9000
# Define the command to run the application
CMD ["sh", "/app/java-playframework/bin/java-playframework"]
</code>
<code># Use an official OpenJDK runtime as a parent image for the build stage
FROM openjdk:11-jdk-slim AS builder
# Set the working directory in the container
WORKDIR /app
# Install necessary tools and sbt
RUN apt-get update && apt-get install -y curl unzip &&
curl -L -o /tmp/sbt.tgz https://github.com/sbt/sbt/releases/download/v1.4.7/sbt-1.4.7.tgz &&
mkdir -p /usr/local/bin/sbt &&
tar -xzf /tmp/sbt.tgz -C /usr/local/bin/sbt --strip-components=1 &&
ln -s /usr/local/bin/sbt/bin/sbt /usr/bin/sbt &&
rm /tmp/sbt.tgz
# Copy the application code to the container
COPY . /app
# Build the application
RUN sbt dist
# Use an official OpenJDK runtime as a parent image for the runtime stage
FROM openjdk:11-jre-slim
# Set the working directory in the container
WORKDIR /app
# Copy the distribution zip file from the builder stage
COPY --from=builder /app/target/universal/*.zip /app/
# Extract the distribution zip file
RUN apt-get update && apt-get install -y unzip &&
unzip /app/*.zip &&
rm /app/*.zip
# Expose the port that the Play app runs on
EXPOSE 9000
# Define the command to run the application
CMD ["sh", "/app/java-playframework/bin/java-playframework"]
</code>
# Use an official OpenJDK runtime as a parent image for the build stage
FROM openjdk:11-jdk-slim AS builder
# Set the working directory in the container
WORKDIR /app
# Install necessary tools and sbt
RUN apt-get update && apt-get install -y curl unzip &&
curl -L -o /tmp/sbt.tgz https://github.com/sbt/sbt/releases/download/v1.4.7/sbt-1.4.7.tgz &&
mkdir -p /usr/local/bin/sbt &&
tar -xzf /tmp/sbt.tgz -C /usr/local/bin/sbt --strip-components=1 &&
ln -s /usr/local/bin/sbt/bin/sbt /usr/bin/sbt &&
rm /tmp/sbt.tgz
# Copy the application code to the container
COPY . /app
# Build the application
RUN sbt dist
# Use an official OpenJDK runtime as a parent image for the runtime stage
FROM openjdk:11-jre-slim
# Set the working directory in the container
WORKDIR /app
# Copy the distribution zip file from the builder stage
COPY --from=builder /app/target/universal/*.zip /app/
# Extract the distribution zip file
RUN apt-get update && apt-get install -y unzip &&
unzip /app/*.zip &&
rm /app/*.zip
# Expose the port that the Play app runs on
EXPOSE 9000
# Define the command to run the application
CMD ["sh", "/app/java-playframework/bin/java-playframework"]
build.sbt
<code>name := """hello-world"""
organization := "com.example"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.13.14"
libraryDependencies += guice
</code>
<code>name := """hello-world"""
organization := "com.example"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.13.14"
libraryDependencies += guice
</code>
name := """hello-world"""
organization := "com.example"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.13.14"
libraryDependencies += guice
Error
<code>194.9 [info] welcome to sbt 1.10.0 (Oracle Corporation Java 17.0.2)
199.4 [info] loading settings for project app-build from plugins.sbt ...
201.1 [info] loading project definition from /app/project
239.5 [info] set current project to app (in build file:/app/)
239.8 [error] Not a valid command: dist (similar: set, iflast, last)
239.8 [error] Not a valid project ID: dist
239.8 [error] Expected ':'
239.8 [error] Not a valid key: dist (similar: bgList, test, history)
239.8 [error] dist
</code>
<code>194.9 [info] welcome to sbt 1.10.0 (Oracle Corporation Java 17.0.2)
199.4 [info] loading settings for project app-build from plugins.sbt ...
201.1 [info] loading project definition from /app/project
239.5 [info] set current project to app (in build file:/app/)
239.8 [error] Not a valid command: dist (similar: set, iflast, last)
239.8 [error] Not a valid project ID: dist
239.8 [error] Expected ':'
239.8 [error] Not a valid key: dist (similar: bgList, test, history)
239.8 [error] dist
</code>
194.9 [info] welcome to sbt 1.10.0 (Oracle Corporation Java 17.0.2)
199.4 [info] loading settings for project app-build from plugins.sbt ...
201.1 [info] loading project definition from /app/project
239.5 [info] set current project to app (in build file:/app/)
239.8 [error] Not a valid command: dist (similar: set, iflast, last)
239.8 [error] Not a valid project ID: dist
239.8 [error] Expected ':'
239.8 [error] Not a valid key: dist (similar: bgList, test, history)
239.8 [error] dist