我想從我在ideallij中創建的javafx項目導出jar文件。我通過在輸出中添加所有的jar庫來完成工件的屬性。然後,我構建了工件並創建了jar文件。在FXML文件在導出的jar文件中添加fxml文件
Exception in Application start method, java.lang.reflect.InvocationTargetException
錯誤點:然而,當我試圖用java - jar name.jar
運行來自終端的罐子我收到以下錯誤。我怎樣才能在壓縮的jar文件中添加fxml文件?
FXML加載:
public void start(Stage primaryStage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader(EchoClient.class.getResource("name.fxml"));
Parent p = fxmlLoader.load();
Scene scene = new Scene(p);
primaryStage.setScene(scene);
primaryStage.setTitle("FX Echo Client");
primaryStage.setWidth(320);
primaryStage.setHeight(568);
primaryStage.show();
}
錯誤位於Parent p = fxmlLoader.load();
.The錯誤我收到如下:
編輯:後有點研究,我來到結論是我的問題與following post一致。因此,我刪除了從FXML文件中刪除fx:controller
屬性,並且該jar通常在沒有應用程序功能的情況下調用。如何將控制器功能添加回代碼?
我FXML文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="services.EchoClientController">
<children>
<VBox spacing="10.0" VBox.vgrow="SOMETIMES">
<children>
<Label text="Host" />
<TextField fx:id="tfHost" text="localhost" />
<Label text="Port" />
<TextField fx:id="tfPort" text="10000" />
<HBox spacing="4.0">
<children>
<Button fx:id="btnConnect" mnemonicParsing="false" onAction="#connect" text="Connect" />
<Button fx:id="btnDisconnect" mnemonicParsing="false" onAction="#disconnect" text="Disconnect" />
</children>
</HBox>
</children>
<VBox.margin>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</VBox.margin>
</VBox>
<Separator prefWidth="200.0" />
<VBox spacing="10.0" VBox.vgrow="ALWAYS">
<children>
<Label text="Message To Send" />
<TextField fx:id="tfSend" />
<Button fx:id="btnSend" mnemonicParsing="false" onAction="#send" text="Send" />
<Label text="Message Received" />
<TextField fx:id="tfReceive" editable="false" />
</children>
<VBox.margin>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</VBox.margin>
</VBox>
<Separator prefWidth="200.0" />
<VBox VBox.vgrow="NEVER">
<VBox.margin>
<Insets bottom="10.0" left="20.0" right="20.0" top="10.0" />
</VBox.margin>
<children>
<HBox fx:id="hboxStatus" spacing="10.0">
<children>
<ProgressBar fx:id="piStatus" prefWidth="150.0" progress="0.0" />
<Label fx:id="lblStatus" text="Label" />
</children>
</HBox>
</children>
</VBox>
</children>
</VBox>
至少告訴我們如何通過代碼加載fxml文件。 – JKostikiadis
我更新了代碼。 – konstantin
那麼你仍然需要向我們展示你的項目設置文件的位置,你的包等。 – JKostikiadis