我面临的问题是这段代码可以在intellij IDE中完美运行,但是在创建jar一段时间后,我们在将fxml文件加载到窗格中时遇到了加载异常:
javafx.fxml.LoadException:/../../..Toolbar.fxml
或
NoClassDefFound
许多次都可以正常工作,没有任何例外。我们无法确定它什么时候起作用,什么时候不起作用。当我们人为减少虚拟机的RAM时,它的发生频率更高。所以
private void topView(){
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(this.getClass().getResource("View/Toolbar/ToolBar.fxml"));
AnchorPane pane = loader.load();
Methods.setBackGroundColor(pane);
rootPane.setTop(pane);
variablesObj.setToolbarObj(loader.getController());
} catch (IOException e) {
logger.Error("Error", "Could not find file", e + " Error");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.*?>
<?import javafx.sc lnene.control.Label?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<AnchorPane fx:id="MainPaneTool" prefHeight="80.0" prefWidth="722.0" style="-fx-background-color: #ffffff;" xmlns="http://javafx.com/javafx/8.0.162" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.tetcos.NetSim.Simulation.View.Toolbar.ToolBarController">
<AnchorPane fx:id="parentPane" layoutY="25.0" prefHeight="80.0" prefWidth="200.0" />
<HBox fx:id="hBox" layoutY="25.0" prefHeight="80.0" style="-fx-background-color: #ffffff;">
<AnchorPane fx:id="dAnchorPane" prefHeight="80.0" prefWidth="80" />
<AnchorPane fx:id="lAnchorPane" prefHeight="80.0" prefWidth="105.0">
<Line endY="80.0" fill="#8d8686" layoutX="1.0" layoutY="5.0" opacity="0.2" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="0.5" AnchorPane.rightAnchor="130.5" AnchorPane.topAnchor="5.0" />
<JFXButton fx:id="MLButton" layoutY="0.0" prefHeight="10.0" prefWidth="130.0" ripplerFill="#777777" text="Adhoc Link" AnchorPane.leftAnchor="2" />
<JFXButton fx:id="PLButton" layoutY="30.0" prefHeight="1.0" prefWidth="130.0" ripplerFill="#777777" text="Wired/Wireless" AnchorPane.leftAnchor="2" />
<Label fx:id="lable" alignment="CENTER" layoutY="58.0" prefHeight="14" prefWidth="130" text="Links" AnchorPane.bottomAnchor="3.0" AnchorPane.topAnchor="58.0" />
</AnchorPane>
<AnchorPane fx:id="appAnchorPane" prefHeight="80.0" prefWidth="98.0">
<Line endY="80.0" layoutX="1.0" layoutY="5.0" opacity="0.2" AnchorPane.bottomAnchor="5.0" AnchorPane.topAnchor="5.0" />
<JFXButton fx:id="appButton" contentDisplay="TOP" layoutX="5.0" layoutY="11.0" prefHeight="73.0" prefWidth="90.0" ripplerFill="#777777" text="Application" />
</AnchorPane>
<AnchorPane fx:id="tAnchorPane" prefHeight="80.0" prefWidth="120.0">
<Line endY="80.0" layoutX="1.0" layoutY="5.0" opacity="0.2" AnchorPane.bottomAnchor="5.0" AnchorPane.topAnchor="5.0" />
<JFXButton fx:id="dMetricsButton" prefHeight="10.0" prefWidth="120.0" ripplerFill="#777777" text="Plots" />
<JFXButton fx:id="pTrakeButton" layoutY="28.0" prefHeight="1.0" prefWidth="120.0" ripplerFill="#777777" text="Packet Trace" />
<JFXButton fx:id="eTrakeButton" layoutY="56.0" prefHeight="14.0" prefWidth="120.0" ripplerFill="#777777" text="Event Trace" />
</AnchorPane>
<AnchorPane prefHeight="80.0" prefWidth="80.0">
<Line endY="80.0" layoutX="1.0" layoutY="5.0" opacity="0.2" AnchorPane.bottomAnchor="5.0" AnchorPane.topAnchor="5.0" />
<JFXButton fx:id="runButton" contentDisplay="TOP" layoutX="5.0" layoutY="11.0" prefHeight="73.0" prefWidth="73.0" ripplerFill="#777777" text="Run" />
</AnchorPane>
<AnchorPane fx:id="viewAnchorPane" prefHeight="80.0" prefWidth="140.0">
<Line endY="80.0" layoutX="1.0" layoutY="5.0" opacity="0.2" AnchorPane.bottomAnchor="5.0" AnchorPane.topAnchor="5.0" />
<JFXButton fx:id="viewAniButton" layoutX="2.0" prefHeight="17.0" prefWidth="140.0" ripplerFill="#777777" text="View Animation" />
<JFXButton fx:id="viewResultsButton" layoutX="2.0" layoutY="28.0" prefHeight="1.0" prefWidth="140.0" ripplerFill="#777777" text="View Results" />
<JFXButton fx:id="viewInfoButton" layoutX="3.0" layoutY="56.0" prefHeight="16.0" prefWidth="140.0" ripplerFill="#777777" text="Display Settings" />
</AnchorPane>
</HBox>
<AnchorPane fx:id="menuPane" prefHeight="25.0" prefWidth="200.0" style="-fx-background-color: #ffffff;" />
<Line fx:id="menubarLine" endX="100.0" endY="25.0" startY="25.0" strokeWidth="0.15" />
</AnchorPane>
public class ToolBarController {
@FXML
private JFXButton PLButton;
@FXML
private JFXButton MLButton;
@FXML
private JFXButton appButton;
@FXML
private JFXButton dMetricsButton;
@FXML
private JFXButton pTrakeButton;
@FXML
private JFXButton eTrakeButton;
@FXML
private JFXButton runButton;
@FXML
private JFXButton viewAniButton;
@FXML
private JFXButton viewResultsButton;
@FXML
private JFXButton viewInfoButton;
@FXML
private AnchorPane dAnchorPane;
@FXML
private AnchorPane parentPane;
@FXML
private AnchorPane lAnchorPane;
@FXML
private AnchorPane viewAnchorPane;
@FXML
private AnchorPane tAnchorPane;
@FXML
private AnchorPane appAnchorPane;
@FXML
private AnchorPane MainPaneTool;
@FXML
private HBox hBox;
@FXML
private AnchorPane menuPane;
@FXML
private Line menubarLine;
@FXML
private void initialize() {
Menubar menubarObj = new Menubar();
menubarObj.initializeMenu(menuPane);
linkAnchorPane.getChildren().remove(P2PLinkButton);
linkAnchorPane.getChildren().remove(M2MLinkButton);
applicationAnchorPane.getChildren().remove(applicationButton);
traceAnchorPane.getChildren().remove(packetTraceButton);
traceAnchorPane.getChildren().remove(eventTraceButton);
traceAnchorPane.getChildren().remove(dynamicMetricsButton);
//Now adding sub anchor pane in dAnchorPane, lAnchorPane, viewInfoButton
//based on database. I can't share that code.
}