"Actual" Answer
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 <path-to-jar-file>
Rest of Answer
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:
---<project-directory>
+---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):
Non-modular
Exploded Directory
java -p "%PATH_TO_FX%" --add-modules javafx.controls -cp outclasses com.example.Main
Jar File
java -p "%PATH_TO_FX%" --add-modules javafx.controls -jar outartifactsapp-1.0.jar
Note: Requires Main-Class
attribute in the manifest.
Modular
Exploded Directory
java -p "%PATH_TO_FX%;outclasses" -m app/com.example.Main
Jar File
java -p "%PATH_TO_FX%;outartifacts" -m app/com.example.Main
Or if the Jar was created/updated with --main-class
java -p "%PATH_TO_FX%;outartifacts" -m app
Notes:
- The above assumes that
<project-directory>
is the working directory.
-p
is shorthand for --module-path
-m
is shorthand for --module
-cp
is shorthand for --class-path
or -classpath
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…