My first question on stackoverflow:
I'm on MacOS BigSur 11.5.2, 2.3 GHz Dual-Core i5, 8GB. I'm using Eclipse IDE for Java, v4.17. I've downloaded and configured the JavaFX SDK (v11.0.2) from gluonhq.com
I'm attempting to run a basic JavaFX HelloWorld program (very common, seen it everywhere). When I run this program, all it does is open a blue Java folder in my desktop's task bar; it doesn't open a new UI window titled "Hello World".
I've added the JavaFX SDK external library to the project's build path.
I've specified the correct path to the JavafX SDK in the Run Config's vm arguments.
--module-path /Documents/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml
I've ensured javafx.controls and javafx.fxml module dependencies are recognized in the Run Config (I assume all necessary
requires transitive
modules are encompassed here).
here is my Main.java class
package com.me.jfxapplication;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = javafx.fxml.FXMLLoader.load(getClass().getResource("Sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
here is my Sample.fxml file
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.GridPane?>
<GridPane fx:controller="com.cowsill.jfxapplication.Controller"
xmlns:fx="javafx.com/fxml" alignment="center" hgap="10" vgap="10">
</GridPane>
here is my module-info.java
module com.me.jfxapplication {
exports com.me.jfxapplication;
requires javafx.base;
requires javafx.fxml;
requires javafx.graphics;
}
I've also attempted to run this on the command line via the following:
javac --module-path ~/Documents/javafx-sdk-11.0.2/lib/ --add-modules javafx.controls,javafx.fxml jfxapplication/Main.java
java --module-path ~/Documents/javafx-sdk-11.0.2/lib/ --add-modules javafx.controls,javafx.fxml jfxapplication/Main.java
After scouring web resources, there seem to a lot of repeat issues regarding module dependencies with JFX. I went through every instance of the problem that others were having and and mirrored every bug fix they suggested. My program is running yes? it's just not displaying the scene graph/UI.
Thanks!
Main
class to be located atcom/me/jfxapplication/Main.java
. Yet you seem to indicate it's located atjfxapplication/Main.java
. (2) You don't appear to be compiling themodule-info.java
file. (3) As your application appears to have amodule-info.java
file you shouldn't need to use--add-modules
. And you should be launching your application as a module via the--module <main-module>[/<main-class>]
option. – Slawjava
command is still wrong. You should be passing the fully qualified class name, not the source file, at the end. Socom.me.jfxapplication.Main
, notjfxapplication/Main.java
. I can't promise these issues are related to your problem though. – Slaw--add-modules
for those jar's, but it returns 'error: package javafx.scene does not exist' and '...javafx.stage does not exist'. – Therius_Traxdominusexport PATH_TO_FX=path/to/javafx-sdk-15.0.1/lib
... because when entering this command, it returns 'export: PATH_TO_FX=path/to/javafx-sdk-15.0.1/lib: not a valid identifier'. I've ensured my path_to_fx is accurate – Therius_Traxdominus