Прошу совет по сборке javaFX в jar файл. При работе в intellij idea тестирование проекта работает и приложение открывается, но при сборке jar файла приложение не запускается. Использую jdk-17 и javafx-17.
public class Application extends javafx.application.Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(Application.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 900, 630);
stage.setResizable(false);
stage.setTitle("Конвертер");
stage.setScene(scene);
stage.getIcons().add(new Image(Path.of("src/main/Source/Icon.png").toAbsolutePath().toString()));
stage.show();
}
public static void main(String[] args) {
launch();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Файл .fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="628.0" prefWidth="912.0" style="-fx-background-color: #F4F7FB;" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.demo.Controller">
<children>
<AnchorPane prefHeight="628.0" prefWidth="238.0" style="-fx-background-color: #FFF;">
<children>
<Text fill="#1a1b1a" layoutX="48.0" layoutY="48.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Конвертер">
<font>
<Font name="Segoe Print Bold" size="24.0" />
</font>
</Text>
<ImageView fitHeight="150.0" fitWidth="200.0" layoutX="44.0" layoutY="60.0" pickOnBounds="true" preserveRatio="true" style="-: #fff;">
<image>
<Image url="file:/C:/Users/Dipsy/IdeaProjects/NumberSystemConverter/src/main/Source/calculator.png" />
</image>
</ImageView>
<Separator layoutX="19.0" layoutY="229.0" prefHeight="10.0" prefWidth="200.0" style="-fx-background-color: #ccc; -fx-border-color: #333; -fx-border-style: solid;" />
<Text fill="#1a1b1a" layoutX="8.0" layoutY="310.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Приложение разработано для облегчения усвоения пройденого материала по системам счисления в учебных заведениях" textAlignment="CENTER" wrappingWidth="222.0">
<font>
<Font name="Segoe Print Bold" size="14.0" />
</font>
</Text>
</children>
<effect>
<DropShadow />
</effect>
</AnchorPane>
<RadioButton fx:id="GroupOneBin" layoutX="313.0" layoutY="219.0" mnemonicParsing="false" text="Двоичная">
<toggleGroup>
<ToggleGroup fx:id="GroupOne" />
</toggleGroup>
</RadioButton>
<RadioButton fx:id="GroupOneOct" layoutX="313.0" layoutY="267.0" mnemonicParsing="false" text="Восьмеричная" toggleGroup="$GroupOne" />
<RadioButton fx:id="GroupOneDec" layoutX="313.0" layoutY="317.0" mnemonicParsing="false" text="Десятичная" toggleGroup="$GroupOne" />
<RadioButton fx:id="GroupOneHex" layoutX="313.0" layoutY="363.0" mnemonicParsing="false" text="Шестнадцатеричная" toggleGroup="$GroupOne" />
<RadioButton fx:id="GroupTwoBin" layoutX="634.0" layoutY="219.0" mnemonicParsing="false" text="Двоичная">
<toggleGroup>
<ToggleGroup fx:id="GroupTwo" />
</toggleGroup>
</RadioButton>
<RadioButton fx:id="GroupTwoOct" layoutX="634.0" layoutY="267.0" mnemonicParsing="false" text="Восьмеричная" toggleGroup="$GroupTwo" />
<RadioButton fx:id="GroupTwoDec" layoutX="634.0" layoutY="317.0" mnemonicParsing="false" text="Десятичная" toggleGroup="$GroupTwo" />
<RadioButton fx:id="GroupTwoHex" layoutX="634.0" layoutY="363.0" mnemonicParsing="false" text="Шестнадцатеричная" toggleGroup="$GroupTwo" />
<Button fx:id="calculateBtn" layoutX="438.0" layoutY="549.0" mnemonicParsing="false" prefHeight="53.0" prefWidth="182.0" text="Вычеслить">
<font>
<Font name="Segoe Print" size="18.0" />
</font>
</Button>
<TextArea fx:id="tablo" layoutX="412.0" layoutY="22.0" prefHeight="30.0" prefWidth="262.0" />
<Text fill="#1a1b1a" layoutX="288.0" layoutY="50.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Введите число">
<font>
<Font name="Segoe Print Bold" size="14.0" />
</font>
</Text>
</children>
</AnchorPane>
Если запускать jar файл через командную строку то выпадает исключение :
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:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalArgumentException: Invalid URL: unknown protocol: c
at javafx.graphics/javafx.scene.image.Image.validateUrl(Image.java:1135)
at javafx.graphics/javafx.scene.image.Image.<init>(Image.java:625)
at com.example.demo.Application.start(Application.java:18)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
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:184)
... 1 more
Caused by: java.net.MalformedURLException: unknown protocol: c
at java.base/java.net.URL.<init>(URL.java:681)
at java.base/java.net.URL.<init>(URL.java:569)
at java.base/java.net.URL.<init>(URL.java:516)
at javafx.graphics/javafx.scene.image.Image.validateUrl(Image.java:1132)
... 11 more
Exception running application com.example.demo.Application