0

Estava desenvolvendo uma calculadora em Java, para estudar a linguagem. Após fazer todo o projeto e exportar o arquivo .jar e tentar executá-lo, nada acontece. Ao tentar executar no terminal pelo comando java -jar NomeDoArquivo.jar, é retornado a seguinte mensagem Error: JavaFX runtime components are missing, and are required to run this application. Até aí ok, problemas na runtime. Ao tentar usar o comando java --module-path oCaminhoDaRuntime --add-modules javafx.controls -jar NomeDoArquivo.jar é retornado o seguinte erro:

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x79bba58a) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x79bba58a
    at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
    at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
    at application.MainCalculator.initRootLayout(MainCalculator.java:23)
    at application.MainCalculator.start(MainCalculator.java:19)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
    ... 1 more
Exception running application application.MainCalculator

Já procurei aqui, no stack gringo, no Google e não consegui encontrar nada que resolvesse ou indicasse uma possível resolução desse problema. Segue o código da classe main:

package application;
    
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.Parent;
import javafx.scene.Scene;


public class MainCalculator extends Application {
    public static Stage primaryStage;
    public static Parent rootLayout;
    
    @Override
    public void start(Stage stage) throws Exception {
        primaryStage = stage;
        
        initRootLayout();
    }
    
    public void initRootLayout() throws Exception {
        rootLayout = FXMLLoader.load(getClass().getResource("view/RootLayout.fxml"));
        
        Scene scene = new Scene(rootLayout);
        primaryStage.initStyle(StageStyle.UNDECORATED);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    
    public static void main(String[] args) {
        launch(args);
    }
}```
1
  • Qual a versão do Java?
    – user201641
    Commented 14/12/2020 às 19:52

1 Resposta 1

0

Resolvi parte do problema. Meu SO (Ubuntu 20.04) estava usando a JDK da Oracle. Quando mudei pra OpenJDK, funcionou usando o java --module-path oCaminhoDaRuntime --add-modules javafx.controls,javafx.fxml -jar NomeDoArquivo.jar

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .