I downloaded:
- OpenJDK 11.0.2
- JavaFX SDK 11.0.2
Both files are extracted to path C:/Program Files/Java/
OS: Windows 10
IDE:
Some of those errors you've provided indicate a problem with spaces in your arguments (e.g. C:/Program Files/...
). Surround %PATH_TO_FX%
with quotes: "%PATH_TO_FX%"
. Then, as you said in a comment, the correct command line for you is:
java -p "%PATH_TO_FX%" --add-modules javafx.controls -jar
From the information you've provided, it's difficult (for me at least) to tell what exactly the problem is. Instead, I'll give some examples of launching a JavaFX application from the command line, both modular and non-modular.
Let's say you have a project with one class—the main class—named com.example.Main
. This class extends Application
and displays a simple window. Let's also say that, when the code is modular, the module looks like:
module app {
requires javafx.controls;
exports com.example to javafx.graphics;
}
And your project structure looks like this:
\---
+---out
| +---artifacts
| | app-1.0.jar (modular or non-modular)
| |
| \---classes
| | module-info.class (when modular)
| |
| \---com
| \---example
| Main.class
|
\---src
| module-info.java (when modular)
|
\---com
\---example
Main.java
Then your command line will look like one of the following (Windows oriented):
java -p "%PATH_TO_FX%" --add-modules javafx.controls -cp out\classes com.example.Main
java -p "%PATH_TO_FX%" --add-modules javafx.controls -jar out\artifacts\app-1.0.jar
Note: Requires Main-Class
attribute in the manifest.
java -p "%PATH_TO_FX%;out\classes" -m app/com.example.Main
java -p "%PATH_TO_FX%;out\artifacts" -m app/com.example.Main
Or if the Jar was created/updated with --main-class
java -p "%PATH_TO_FX%;out\artifacts" -m app
Notes:
is the working directory.-p
is shorthand for --module-path
-m
is shorthand for --module
-cp
is shorthand for --class-path
or -classpath