JavaFX jar file throwing exception - javafx

I've just finished my JavaFX project.
In the src file I've got some folders that each includes different files: FXML, CSS, Class, Files, Controllers.
After I build Artifacts in the IntelliJ, when I run it on cmd, the Jar file throws an exception because it can not find the FXML files!
I've copied the FXML folders next to the Jar file and a folder before it but it doesn't work
I've made packages to be clean but it has made some trouble for me!
here is a screenshot of my code
And I've made a fatherController that each controller extends from that and it has a method called load page that's how I load my FXML files

Try calling the FXMLs like this
Parent root = FXMLLoader.load(getClass().getResource("/ContactList/FXML/"+fxmlFileName+".fxml"));

I found the problem! I shouldn't Address the FXML files like the picture.
instead of "../FXML/example.fxml", Is should use "/FXML/example.fxml".

Related

Importing a JAR into SceneBuilder not working

I am using SceneBuilder-9.0.1 and trying to use JFoenix. While trying to import the jfoenix-9.0.1.jar with the JAR/FXML Manager (Library Managger), the following error appears:
I have no problems with importing FXML files though. The same error occurs if I try to import other JARs, e.g. controlsfx.
I think it's strange that the Scene Builder wants to copy the file into \Roaming\Scene Builder/Library because that's no valid file path, isn't it? Is there any way of coyping the file manually without using the Library Manager? And if yes, where do I need to copy the JAR file to? And is this a problem of SceneBuilder or of my PC?
Thanks in advance!

How to include an FXML file in another one in jar?

I am trying to use <fx:include source="abcd.fxml"/> tag but I get Base location is undefined error when launching the application.
If a set the location of FXMLLoader this time it doesn't work in jar files because when a resource is in jar file it's URL is meaningless (because a jar file is a kind of a zip file).
Is there a way to use this include tag even if I deploy my application as a jar file?

javac with MigLayout

I've spent the past week trying to figure this issue out...hopefully someone can help.
I created a Java project that uses MigLayout. I've added the jar file to the same directory where my main class is.
i.e.
java/
Main.java ...contains main() method
MigLayout/miglayout-4.0-swing.jar
It doesn't matter which editor I use, I can compile/run the file and it executes flawlessly.
The issue starts when I try to create a jar file, or compile with cmd. If, for example, in IntelliJ I build the artifact (build the Jar file), it builds it...but it won't run it when I double click on it.
If I use javac in cmd, it gives me this error:
/////////////////////////////////////////////////////////////////////
Main.java:8: error: package net.miginfocom.swing does not exist
import net.miginfocom.swing.MigLayout;
^
Main.java:74: error: cannot find symbol
menuPanel = new JPanel(new MigLayout());
^
symbol: class MigLayout
location: class Main
2 errors
//////////////////////////////////////////////////////////////////////
Any help would be great.
SOLVED
OK, so I got it working. This is what I did:
I created a new folder and moved all of the src files into the src folder there
I made sure to remove all other files that weren't java related, such as the Manifest file
I previously downloaded the MigLayout and json jars and placed them into the src folder as well (that's how I originally got the code to compile)
I opened up IntelliJ and clicked File -> New -> Project from existing source
I selected the folder that contained the src folder
I ran through the prompts. I noticed that it was finding everything: MigLayout and JSON jars
After it was complete, I made sure that it would compile in IntelliJ and it did.
Next, as I did before, I clicked File -> Project Structure -> Artifacts
I clicked the Plus button and selected JAR From Modules with dependencies. I selected the file containing the main method
I checked the Build on make option that's right below the Output directory
I clicked Apply and OK.
Next I clicked Build and Build Artifacts
I selected Jar and Build Jar
Went to the out folder and it was there
I double clicked on it and everything worked!

How to create runnable jar with images and sounds in Eclipse?

I'm trying to create a jar in eclipse. The project contains images and sounds.
I have Resources folder with more folders, but when I run the jar is without the images.
The project structure:
Example:
btServer.setGraphic(new ImageView(new Image("file:Resources/buttonimages/Server.png",100,100,false,false)));
Make sure when you are exporting your Runnable JAR file, you are selecting 'extracting required libraries into generated JAR'.
The other workaround is to put the resources folder from your workspace in the same file location as your jar file.
Hope this helps

Package does not exist - error

I am trying to compile a .java file (TransformRTDE.java) that uses several import statements. These statements import .class files present in five external JAR files: dataextract.jar, jna.jar, JRI.jar, JRIEngine.jar and REngine.jar. I have read documentation on how to deal with these import statements while trying to compile your .java file from the command line. However, I do not seem to succeed.
I set up the directory in the command line to be the folder in which my .java file resides. In that same folder, I have put the JAR files. When I try to compile the code using java -cp dataextract.jar jna.jar JRI.jar JRIEngine.jar REngine.jar TransformRTDE.java, I get a package does not exist error. I have set up the class path to include the folder in which all my .java and .jar files reside.
I have searched for hours on this without success. Any ideas what I'm doing wrong?
Thanks in advance!
EDIT: I forgot to mention I also get an error related to annotation processing.
Picture can be found here: https://www.dropbox.com/s/p9ul0olydzmkl6s/error.png

Resources