Here's a breakdown of the different project components:
src/main/java
: The source code for the project, organized by package:eu.ammbra.bday.Organizer.java
: The main entry point of the application, possibly responsible for coordinating the overall flow of the program.eu.ammbra.bday.details
: A package containing domain model classes. These classes represent entities involved in birthday celebrations, such as cakes, parties, and people attending them.eu.ammbra.bday.handlers
: A package containing classes responsible for handling specific tasks.eu.ammbra.bday.operations
: A package containing classes responsible for handling the operational side of parties.eu.ammbra.bday.store
: A package containing classes responsible for interacting with data from files.
src/main/resources/store/events.json
: A resource file containing sample event data in JSON format.static
: A folder holding client-side related static files.src/test/java
: The source code for unit tests and integration tests.src/snippets
: The JSON snippets folder.
The jdeps
tool analyzes your Java application’s dependencies and provides package or class level details, by identifying:
- dependencies your project actively uses,
- transitive dependencies that your project indirectly relies on,
- missing dependencies that can cause errors.
To leverage jdeps
you need either compiled Java classes (.class
files) or a JAR file. Your task relies on you to do the following steps:
- Open another terminal window and place yourself in
D_bday_jlink
folder. - Let's find all the Java files in the project, store their path in a file and compile them via command-Line argument files (
@sourcefiles.txt
).
# Windows specific commands to get Java files from current directory
dir /s /B *.java > sourcefiles.txt
javac --enable-preview --source 23 -cp "..\lib\*" @sourcefiles.txt -d out
# unix/macOS specific commands to get Java files from current directory
find . -name "*.java" > sourcefiles.txt
javac --enable-preview --source 23 -cp "../lib/*" @sourcefiles.txt -d out
- Get a summary of your dependencies by running:
# unix/macOS specific command
jdeps --multi-release 23 --class-path '../lib/*' -s out/
# Windows specific commands
jdeps --multi-release 23 --class-path '..\lib\*' -s out\
- Observe the output of previous command and check if there are dependencies not found. In such scenarios, is best to scan recursively your files:
# unix/macOS specific command
jdeps --multi-release 23 --class-path '../lib/*' -recursive out/
# Windows specific commands
jdeps --multi-release 23 --class-path '..\lib\*' -recursive out\
- To better observe the output, you can export the dependencies details as a DOT format.
# unix/macOS specific command
jdeps --class-path '../lib/*' --dot-output graph --ignore-missing-deps --multi-release 23 -recursive out/
# Windows specific commands
jdeps --class-path '..\lib\*' --dot-output graph --ignore-missing-deps --multi-release 23 -recursive out\
With tools like https://graphviz.org/ you can visualize the dependencies in a .PNG
or .SVG
file.
- Finally, let's print the output of dependencies in a way that
jlink
could process them directly:
# unix/macOS specific command
jdeps --class-path '../lib/*' --ignore-missing-deps --print-module-deps --multi-release 23 out/
# Windows specific commands
jdeps --class-path '..\lib\*' --ignore-missing-deps --print-module-deps --multi-release 23 out/
Next, let's make sure our application uses the right dependencies.
⚠️ If your terminal is unaware ofjlink
, you may invoke it through$JAVA_HOME/bin/jlink
. All JDK tools are executable from JDK'sbin
folder.
jlink
is a JDK tool that you can use to assemble and optimize a set of modules and their dependencies into a custom runtime image.
Your task relies on you to do the following steps:
- First, let's run
jlink
with the modules discovered in the previous sectionjava.base,java.net.http,java.sql,jdk.httpserver
:
# unix/macOS specific command
jlink --add-modules java.base,java.net.http,java.sql,jdk.httpserver --output javaruntime
# Windows specific commands
jlink --add-modules java.base,java.net.http,java.sql,jdk.httpserver --output javaruntime
- Next, append the previous command with
--no-man-pages --no-header-files
options to exclude man pages and header files. - Finally, enable compression of resources through
--compress=zip-[0-9]
. This option configures the compression of the image, the higher the value the greater the compression. Example compression levels:
zip-0
: No compressionzip-1
: Fastest compressionzip-6
: Defaultzip-9
: Maximum compression
- Check the output in
javaruntime
folder. If you aren't familiar with that content, ask Ana about it.
⚠️ This activity will require you to usedocker
CLI so make sure you have the Docker daemon running on your laptop.
The runtime created at the previous step or the command you obtained at the previous step can be leveraged to standardize deployment of your application. This activity requires you to :
- Open a terminal window at the root of the
lab-jdk-tools
folder, where theDocker
resides. - Ask Ana about the content of the
Docker
file. - Modify the
Dockerfile
content by filling in thejlink
command with missing modules. - Build the container image with a command similar to
docker build --tag organizer:1.0.0 . --no-cache
. - Run the container image with a command like
docker run docker.io/library/organizer:1.0.0
.
Let's deploy the frontend of the application using jwebserver
. Your task relies on you to do the following steps:
- Open a terminal window at the root of the
lab-jdk-tools
folder, where thecompose.yaml
resides. - Inspect the content of the
compose.yaml
file and find where theDockerfile.web
is. - Modify the
Dockerfile.web
to launchjwebserver
from the/web
directory, serving on all interfaces and listening on the appropriate port. - Verify your solution by running the command
docker-compose up --build
from thelab-jdk-tools
folder. - Check the running application in a browser window (http://localhost:8002/).