JavaFX работает с JAR-сборками с ошибками - PullRequest
0 голосов
/ 14 апреля 2020

код, который, похоже, затронут, является следующим классом.

package VennDiagram;



import java.io.File;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;

import javafx.stage.Stage;


//merged

public class View extends Application{
    public static Stage primaryStage;
    public static Scene promptWindow;
    public static Scene refactor;
    public static Scene scene;


    public static void main(String[] args) {
        launch(args);
    }



    @Override
    public void start(Stage stage) throws Exception{
//      System.out.printf("root = %s\n", getClass().getResource("/views/View.fxml"));


        primaryStage = stage;
        Parent root = FXMLLoader.load(getClass().getResource("View.fxml"));
        Parent root2 = FXMLLoader.load(getClass().getResource("openingPage.fxml"));

        //scene = new Scene(root, 900, 650);
        scene = new Scene(root);
        promptWindow = new Scene(root2,1020,580);
        promptWindow.getStylesheets().add(getClass().getResource("openingPage.css").toExternalForm());
        scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
        primaryStage.setOnCloseRequest(event ->{
            quitProgramAlert.display("Confirm Exit", "Are you sure you want to exit?");
            if(!quitProgramAlert.closePressed) {
                event.consume();
            }

        });

        primaryStage.setMinHeight(600);
        primaryStage.setMinWidth(750);
        primaryStage.setTitle("VennDiagram Creator");
        primaryStage.setScene(promptWindow);
        primaryStage.setResizable(false);
        //primaryStage.getIcons().add(0,new Image(getClass().getResourceAsStream("/images/icon.png")));
        primaryStage.show();
    }


}

Ошибки, которые выдаются при его запуске: ...

Exception in Application start method
Exception in thread "main" 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:567)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
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:830)
Caused by: java.lang.NoClassDefFoundError: org/apache/poi/openxml4j/exceptions/InvalidFormatException
        at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3138)
        at java.base/java.lang.Class.getConstructor0(Class.java:3343)
        at java.base/java.lang.Class.newInstance(Class.java:572)
        at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:936)
        at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:980)
        at javafx.fxml/javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:227)
        at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:752)
        at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
        at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
        at VennDiagram.View.start(View.java:36)
        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(AccessController.java:391)
        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.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
        ... 1 more
Caused by: java.lang.ClassNotFoundException: org.apache.poi.openxml4j.exceptions.InvalidFormatException
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:436)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        ... 27 more

я запускаю файл jar используя следующие флаги ...

java -jar --module-path "MY_PATH_TO_MODULES" --add-modules javafx.controls,javafx.fxml,javafx.graphics JAR_NAME.jar

Дополнительная информация: Существует библиотека apache, которая не работает с приложением правильно, что могло бы стать причиной последних ошибок. Но я не могу понять первые несколько.

Все мои файлы F XML находятся в том же пакете, что и класс, который их вызывает. Ошибка в представлении на 36 относится к следующей строке ...

Parent root = FXMLLoader.load(getClass().getResource("View.fxml"));
...