1Z0-811 Exception Handling and Development Tools Practice Question
You are responsible for deploying a Java desktop application that uses JavaFX and various third-party libraries. The application is modular and uses JPMS. To reduce the footprint and startup time, you decide to use jlink to create a custom runtime image that includes only the required modules. The application has a main module `com.myapp` that requires `javafx.controls`, `javafx.base`, and some other modules. After creating the runtime image using the command `jlink --module-path $JAVA_HOME/jmods:lib --add-modules com.myapp --output myapp-image`, you test the image on a development machine, and it works. However, when deploying to a customer's machine, the application fails to start with an error: "Error: Could not find or load main class com.myapp.Main". The customer's machine has no Java installed. The runtime image includes the `com.myapp` module. You verify that the `myapp-image/bin/java` launcher exists. The main class is correctly declared in the module-info.java of `com.myapp`. What is the most likely cause of this error?
⚠ Common exam trap
Candidates often assume the `java` launcher in the runtime image will automatically find the main class from the module descriptor, but in reality, without `--launcher`, the launcher requires explicit module and main class arguments, mimicking the standard `java` command behavior.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use the `--launcher` option in jlink to create a launcher script that automatically runs the main class with the correct module.
The `jlink` tool does not automatically create a launcher script that specifies the main class for the runtime image. Without the `--launcher` option, the generated `java` launcher does not know which module and main class to execute, leading to the 'Could not find or load main class' error when no Java is installed on the customer's machine. Using `--launcher` creates a custom script (e.g., `myapp`) that invokes `java --module com.myapp/com.myapp.Main`, ensuring the correct entry point is used.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use the `--add-modules` option to include `javafx.controls` and other required modules in the command.
Why it's wrong here
The modules are already added; the issue is about launching the main class.
- ✓
Use the `--launcher` option in jlink to create a launcher script that automatically runs the main class with the correct module.
Why this is correct
The `--launcher` option generates a platform-specific script (e.g., myapp.sh or myapp.bat) that invokes the JVM with the correct module and main class, avoiding the need to specify them manually.
- ✗
Add the `--bind-services` option to jlink to automatically include service provider modules.
Why it's wrong here
This does not affect the main class launcher; it is for service binding.
- ✗
Ensure that the `com.myapp` module reads all required modules by adding `requires` directives in module-info.java.
Why it's wrong here
If required modules were missing, the error would be different (e.g., module not found) and the application would have failed on the development machine as well.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.