I have a problem with my JavaFX files. They work perfectly well inside my IDE, but when I build myself a .jar file and try to run it outside of the environment, that's where problems begin...
Double clicking on the file itself does nothing. No communication, no signal, not even command line popping for a slit second. Nothing.
When I try to run it from command line, I get this message:
Error: Could not find or load main class com.javafx.main.Main
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
Here is the mentioned "main.Main" class:
package com.javafx.main;
import com.javafx.controllers.OptionsController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class Main extends Application {
private double x, y;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception{
FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/javafx/screens/rootScreen.fxml"));
StackPane rootStackPane = loader.load();
Scene scene = new Scene(rootStackPane);
primaryStage.setScene(scene);
primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/com/javafx/images/guessingGameIcon.png")));
rootStackPane.setOnMousePressed(mouseEvent -> {
x = mouseEvent.getSceneX();
y = mouseEvent.getSceneY();
});
rootStackPane.setOnMouseDragged(mouseEvent -> {
primaryStage.setX(mouseEvent.getScreenX() - x);
primaryStage.setY(mouseEvent.getScreenY() - y);
});
primaryStage.show();
OptionsController.backgroundMusic();
}
}
- I decided to try and follow this website https://openjfx.io/openjfx-docs/#install-javafx and run the Main.java itself. This is what I received from the command line:
Main.java:3: error: package com.javafx.controllers does not exist
import com.javafx.controllers.OptionsController;
^
Main.java:40: error: cannot find symbol
OptionsController.backgroundMusic();
^
symbol: variable OptionsController
location: class Main
2 errors
I used this command to get the aboved mentioned error:
javac --module-path C:\ ...\javafx-sdk-11.0.2\lib --add-modules javafx.controls,javafx.fxml,javafx.graphics,javafx.media Main.java
I don't know why I have such problems running FX application from outside my environment. And why the same app is working completely fine inside it! If there is someone who could explain the situation, I would be greatfull.