The project works perfectly fine in the IDE. When I convert it to .jar it doesn't work anymore.
Because only the Main2.java
class is converted to jar.
On my project, I have a controller class called Controller2.java
I want to convert the Main2.java
+ the controlleur2.java
files together to a Jar file called final.jar
for example! Because the application requires the controller to work.
How can I do that?
Edit:
When I run the jar file using cmd java -jar fileName.jar
I get this error :
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source) at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source) at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
in the FXML file I have :
<AnchorPane fx:controller="sample.Controller2">
and in Main2.java
I have :
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample2.fxml"));
primaryStage.setTitle("Add new animal");
primaryStage.setScene(new Scene(root, 426, 386));
primaryStage.show();
}