really appreciate your work, these steps should have been specified by Intellij on their website, it really made my day after hours of failed research my project finally works with the jar .. PS this is my first comment on youTube ever since i made my account 10 years ago :D cheers
I've spent at least 10 hours trying to figure out how to do exactly this, trying numerous other tutorials all of which didn't work for me... Unbelievable that it was this simple, and so difficult to find a tutorial explaining this method! Thank you so much!
Thanks to you, I found a solution for MacOS. I added all the ".dylib" files from the "javafx-sdk / lib" directory to the artifact. And it worked the same way as you have with ".dll" files.
Concise and just what I needed to get it working (when it obviously should out of the box). I indeed needed the 'fake' main class + the added DLL to make it auto executable, each one alone wouldn't be enough to make it work. Also for those that let Intellij download the JavaFX files, the default Intellij location for those will be : C:\Users\YOUR_USER\.openjfx\cache There, you will have folders depending on the version of JDK used. For me with JDK 19 it was in a '19+ 11' folder, then amd64, and then all those precisous DLLs Hope it can help more people (and maybe the maintainer at JetBrain or JavaFx update something ? (ಠ﹏ಠ)
You're the greatest. I've spend a day not getting the solution. The internet only talks about adding your sdk folder. Appearantly extending from Application was my error.
I've spent too many hours trying to export it into a jar program and this is the only way that worked for me. All the answers were the same except for the solution in this video and is the one that worked
Thank you so so much. Your Video helped me after already giving up. I think the most tutorials dont tell that you have to add all the .dll files. You safed my day
Huge thanks man) i tried to make a jar-file using maven commands, but it kept throwing out a strange error, google didn't help. But ofc your metod helped me)
It just doesn't work. Jar won't start. I have JavaFX11. (I added a check mark in the place where we added the files) Wow, it works now. You really helped me. I will recommend you 🧐
Thanks a lot! I had to write software for an academic paper for my degree course and couldnt get it to run outside my IDE. If it wasnt for this vid I would not have been able to finish it.
Great video, however in JavaFX 20 you don't need all the files in the bin folder to be included. You only need - glass . dll, javafx_font . dll and prism_d3d . dll if you just have a basic FXML JavaFX application with the 4 main modules (javafx . base, javafx . controls, javafx . graphics and javafx . fxml). If you use more modules you might need more dll dependancies ofc
Sir, I did all the steps but the jar file won't to start or launch .... I have : jdk-17.0.2 and jdk-18.0.1.1 and javafx-sdk-18.0.1. the problem is in Eclipse and Intellij ..... just on javafx but for just java there is no problem. I worked on Swing on Eclipse and the jar file work correctly .... I don't know why in javafx nothing work when I export but and compilation it work well ??!
Check out my newest video it should be what you are looking for: Create executable jar file for JavaFX 15 using Maven: ua-cam.com/video/EyYb0GmtEX4/v-deo.html
Thank you so much, my friend! I have spend the whole evening, trying to figure out, what am I doing wrong and now I see this video! Sry for my bad english...
2:07 where can I download those JavaFX folders? I don't have them and can't seem to find a download link anywhere. I have version 19. On gluonhq There are no .dll files or bin folder for version 19.
Thanks you, it's very helpful !. For those who encounter the error: "Error: JavaFX runtime components are missing, and are required to run this application when export .jar file" when run .jar file with command: "java -jar app.jar". Let's add dependencies in pom.xml: org.openjfx javafx-base 12
Hey, I'm trying to do the same but on Mac OS. I mean I want to build artefacts on Mac OS but I want to run a program in Windows 10. Unfortunately it does not works. The only way I can run a program on windows is use cmd and "java --module-path path/to/fx/lib --add-modules JavaFX.controls, JavaFX.fxml - jar app.jar". I added all DLL's but this does not works :(
@s3nsi milla, I can see you posted another comment but for some reason it is not showing. But regarding your qustion, I am using JavaFX JDK 15 in this video.
Tysm! What a nightmare trying to figure this out. I followed other tutorials but it had to be all of these steps for it to work. I wonder why it doesn't like the "extends Application" in main part...? Thx again!
I am actually not 100% sure. I struggled to get things working, found some random article providing this solution, and then didn't ask any questions. But I would assume there are some hardcoded starting points somewhere causing issues, but that is just my guess.
Help me! I'm trying to build jar file from lesson #17: FileChooser: saving files, but it doesn't work. could someone explain to me why? By the way, thank Random code for this great course! really appreciate your work.
I selected all the files by first clicking on the first file then holding down shift and clicking on the last files, then all files in between will also be selected (I use Windows btw).
Thank you for the video! I am just starting to learn Java. Please tell me, this jar file does not require anything other than JVM? Are all required libraries packed into a jar file?
If the jar file was created with all of its dependencies included, then it should not require any other libraries or dependencies to run other than the JVM. However, if the jar file was created without including all of its dependencies, then it may require other libraries or dependencies to be available on the system to run. In most cases, we can create what is called a fat jar to include all needed dependencies.
Maybe someone runs in to the same problem as me: this didn’t work with java 18 (Oracle OpenJDK version 18.0.1), but it did work with java 17 (Oracle OpenJDK version 17.0.1)
i don't know how to thank you man and i don't know why the other tutorial didn't mention these steps can you please explain what you have done in this video and why you added those files from javaFx sdk ?? and thanks again
I am glad I could help! JavaFX used to be a part of basic Java, however, it was removed from Java 11, we, therefore, need to manually add all the JavaFX functionality to our projects. What we are doing is simply adding java code we can then reference and use like a button or a text field.
Hi! What do you think about to make a video for Kotlin TornadoFx project import to jar with IntelliJ and with gradle? I only found written examples on Stackoverflow and none of them works for me. Thanks in advance!
Glad I could help! We need to get the files from the bin folder because we are creating a normal jar file (Not including JavaFX), we then manually need to get the JavaFX files into the jar file to get it working with JavaFX (the bin folder contains all the JavaFX classes). We cannot just create a JavaFX Jar file because the newer versions of JavaFX have some problems. Hope this explains it :)
@@Randomcode_0 Thank you for your answer ! :) Could you tell me the source where this is explained or documented? I can't find any usefull explanation on IntelliJ or JavaFX (openjfx-docs).
@e s This way of doing it is not a "proper" way, and I doubt any real documentation exists, at least not that I know of. This is just a way it worked for me in the past, I am sorry I cannot give you a better answer :)
This works for a simple program with no additional libraries. My program uses additional libraries such as Lucene for text searching and Java mail for sending messages. My program reads a file at startup as well. Error: Could not find or load main class main.AncestryLaunch Caused by: java.lang.ClassNotFoundException: main.AncestryLaunch
You are very much right, this is a very manual apraoch only working for JavaFX. Building larger and more complex project you should always use a build tool like maven or gradle.
Thank you for your video, helps me a lot. Nevertheless mi application doesn´t find the files (words, html, database) needed to work propertly. It´s seem that all the paths are wrong. I checked the jar file and have the same structure than my proyect, and in IntelliJ it´s work perfect. Any Idea why it´s happening??
You would need your files to have a relative path, which can be used by the project. This means you should place any file you interact with in the resource folder and retrieve them as if they were located there. If this is not the issue, I am not quite sure.
I followed your way and everything worked great beside the init() and stop() methods... is there a way to make them work as normal? or maybe some workaround? I am getting really hard time with it.
Gradle is built on Maven so I would assume it should be possible to achieve the same result with both, however I am not too familiar with Gradle so I can't say for sure.
Hi i did everything exactly the same but the built jar file is not opening not giving even an error, However i built a swing GUI app it works. i have this problem only in JavaFX project.
I am sorry I got no idea why it does not work, and it is very weird it is not giving any errors. The problem regarding JavaFX is that it is no longer supported by the newer versions of Java.
when i run the artifacts which I built, the image and txt file can't be loaded. it said "path" (The system cannot find the path specified). but if I run on intelliJ, it completely normal. I dont understand why. Can u explain it for me
I would assume it is because you access your files using a relative path or the full, path which would be changed when you build you program. You should put text and images inside a resource folder, you then need to access your files through the resource folder, which will stay the same when you build you project. I got a video about this topic: ua-cam.com/video/ABXiJkCcevc/v-deo.html
@@Randomcode_0 i do exactly the same as you but i still get "Cannot invoke "java.net.URL.getPath()" because the return value of "java.lang.Class.getResource(String)" is null". In my resources i have 1 package, i have put my txt file inside it and even outside that package (but still in resource). If i just create a java project then do like you is ok but with javaFX i dont understand why
@@Randomcode_0 sorry my mistake :))) i dont know why when i use in class which is not main although i have add "Main.class" before getResource it didnt run but in Main file it run perfectly. Anyway tks you very much
We do it with JavaFX because it is no longer supported by newer versions of Java, it should not be necessary to add every library, but it depends on the library. I sadly cannot give you a real answer, because it depends, we need to add everything that is not supported by the JDK we use.
@@Randomcode_0 Oh yes, I forgot they parted JavaFX from Java in the newer version, ok I'll try the good ol' brute force when the time comes for executable build :D
Thanks Sir but i have observed that when u have different package and u build its does not run. When is it appropriate to build jar file when the project is completed or as you are developing or at the initial stage
I am not 100% sure when it is "correct" to use jar files. You should think of a jar file kind of like the ZIP file format, which means we use to compress a project into one file which we can then send to other to reduce loss of data. Takle a look at the Java Documentation for more information: docs.oracle.com/javase/8/docs/technotes/guides/jar/jarGuide.html
I create jar using uaing this video.but i converting it into exe using launch4j get error as jni error occured.problem is in my jre.how to fix that.please help dear.
Thanks for the video! When I launch the jar nothing happens and when I look at the error message it gives me "Error: Could not find or load main class com.traptricker.etherminetrackerjavafx.Main_1 Caused by: java.lang.ClassNotFoundException: com.traptricker.etherminetrackerjavafx.Main_1". Do you know how I fix this?
it doesn't work for me. my JDK version is 16 and OpenJFX 17. I guess there some bugs to be fixed in my version. or i have some configuration errors or it is all about the version I've been used.
This is brilliant, thanks so much! I've tried it out with a simple JavaFX project and can now run it from my terminal, no IDE needed. One quick q - if I have a project that reads from / writes to a .txt file how can I include that in the build please?
I am not sure how it would work if you have a file in your resource folder and then just read and write to it using the resource folder as the destination you need to use in your jar. As far as I understand this should still work in a JAR, but I could be wrong. In larger projects, you would connect your project to a database, which is an entirely different world of its own.
I have not been able to find a proper solution to your problem. My best suggestion would be to use something like Maven or Gradle to try building you Jar file.
Just add the .so files from the bin folder. Most of them start with "lib" but aside from that, the filenames are the same. (You'll be missing some "api-****.dll" files but that's fine, you don't need those on linux)
I constantly get this Error: A JNI error has occured, please check your installation and try again. Although I can run my program in Intellij normally. Any clues? Cheers!
I have never had this problem myself, after reading a bit about you error message, it seems to be a problem regarding your java version on your computer. Found this page trying to solve the problem: webdeasy.de/en/error-a-jni-error-has-occured-how-to-fix-this-java-error/ Hope it helped I sadly cannot give any better solution :)
@@simonhutchinson2723 I managed to fix this error, I followed the link above and I was using OpenJ9, once I changed it to the correct javaw.exe I checked that my JRE/JDK and SDK where the same. They weren't my java was 1.8.0 and my SDK was openjdk 15, once i switched my SDK to 1.8 after a rebuild of the project it finaly worked. I hope I wasn't too late to help if it helps at all :)
There are quite a few reasons you could get this error. The simplest solution would be that you have the Main_1 class in the wrong package, it needs to be in src. You could also try removing the underscore from the name because it sometimes is a problem with some operating systems. If this isn’t the case, I do not know why it is not working.
@@Randomcode_0 i created and new project and it runs smoothly, my bad sir. I think my project is broken because i changed the jdk. Thankyou very much :D EDIT: After some research about Could not find or load main class error. In my case, this is because sql server driver 9.2. Tried to remove it and it works or downgrading the sql server driver.
@@Randomcode_0 I tried it, instead of dlls, in mac lib folder i have .jar, .dylib, as well as .properties file, i just put all those to the project and run just fine.
A StackOverflowError is a runtime error in java. It is thrown when the amount of memory allocated is exceeded. A common case of a StackOverflowError being thrown, is when call stack exceeds due to excessive, deep or infinite recursion.
I am using 15.0.1 It is a problem where the Java versions in your program does not exist on your computer. I had a friend who had the JNI problem as well, he need Java SE Development Kit 15.0.1 downloaded to run the versions build with 15.0.1. Where to download Java Development Kits www.oracle.com/java/technologies/javase/jdk15-archive-downloads.html I also had someone else having the same problem using this: webdeasy.de/en/error-a-jni-error-has-occured-how-to-fix-this-java-error/
When i start it with command prompt I get this message: no main manifest attribute, in Restoran.jar Even tho I have manifest.mf file: Manifest-Version: 1.0 Main-Class: Main_1 Do you know what could be the problem?
It might be because do not define in which package your main class is located. If you main class was located inside com.mypackage it would look like this: "Main-Class: com.mypackage.MyMainClass"
really appreciate your work, these steps should have been specified by Intellij on their website, it really made my day after hours of failed research my project finally works with the jar .. PS this is my first comment on youTube ever since i made my account 10 years ago :D cheers
Thank you so much! It is an honor to be your first comment in 10 years :D
I strongly agree with you. It was not about hours... It was about days!😝
Good job!
I've spent at least 10 hours trying to figure out how to do exactly this, trying numerous other tutorials all of which didn't work for me... Unbelievable that it was this simple, and so difficult to find a tutorial explaining this method! Thank you so much!
Glad I could help! I had the same problem, and when I then finally found a decent solution, I thought I would share it.
Thanks to you, I found a solution for MacOS. I added all the ".dylib" files from the "javafx-sdk / lib" directory to the artifact.
And it worked the same way as you have with ".dll" files.
Nice work!
I've been trying to export an available jar for one day till I found this video... Thanks A LOT!!!! It helps me and save me A LOT of time.
Amazing!
This is the first way I have found that actually works. You are a hero. Now feel like i have completed Java! Thank you much.
I am glad I could help!
even the intellij web site did not give the solution to solve this problem ...thank you very very much
I am just very happy I could help :)
God bless you brother, for 6 days i was figuring out why it was not working but it was so simple and I can finally move on. Thank you
I'm glad you figured it out! Wishing you the best as you move forward.
Dosent work for me
As others have stated, the amount of time that I have spent on this is insane. Thank you so very much, you have ended my suffering!
I don't beleive that creating ANOTHER class will help. such a bruh moment. BUT IT ACTUALLY WORKED. Ty
Bruh!
Tysm. Not even GPT was explaining this correctly to me.
I tried 3 days to get an executable file. Now it works. Thanks for your video!😀
Glad my video helped! Congrats on getting the executable file! 😀
Concise and just what I needed to get it working (when it obviously should out of the box). I indeed needed the 'fake' main class + the added DLL to make it auto executable, each one alone wouldn't be enough to make it work.
Also for those that let Intellij download the JavaFX files, the default Intellij location for those will be : C:\Users\YOUR_USER\.openjfx\cache
There, you will have folders depending on the version of JDK used. For me with JDK 19 it was in a '19+ 11' folder, then amd64, and then all those precisous DLLs
Hope it can help more people (and maybe the maintainer at JetBrain or JavaFx update something ? (ಠ﹏ಠ)
You're the greatest. I've spend a day not getting the solution. The internet only talks about adding your sdk folder. Appearantly extending from Application was my error.
Glad to hear I was able to help!
I've spent too many hours trying to export it into a jar program and this is the only way that worked for me. All the answers were the same except for the solution in this video and is the one that worked
It can sometimes be a bit magical, I'm just glad yo hear you got it working!
It worked!! I can't believe that it worked, after weeks trying to find an answer, it finally worked! You're a lifesaver!
Great!
Thank you so so much. Your Video helped me after already giving up. I think the most tutorials dont tell that you have to add all the .dll files. You safed my day
Glad it helped!
Huge thanks man) i tried to make a jar-file using maven commands, but it kept throwing out a strange error, google didn't help. But ofc your metod helped me)
Glad I could help!
It just doesn't work. Jar won't start. I have JavaFX11. (I added a check mark in the place where we added the files) Wow, it works now. You really helped me. I will recommend you 🧐
Good to hear! :)
Thanks a lot! I had to write software for an academic paper for my degree course and couldnt get it to run outside my IDE. If it wasnt for this vid I would not have been able to finish it.
Wow! I am glad I could help and good luck regarding you academic paper!
Thank you! I searched for the solution for a long time, your video helped me!
Glad it helped!
Thank you sooooo much!!! Ive been searching internet for this for so long.
Glad I could help! :)
It works, thanks dude. I have another solution using excel and some files but this is clean
Great to hear! It is always good to search for new and different solutions.
really appreciate your work , keep creating this type of videos
thanks man, you helped me a lot. I was struggling with this problem for about 4 hours now... Thank you
Glad it helped!
This vide saved me at least 3 times :D I allways run into this problem and then im searching for this video :D best video on the internet.
Great to hear! I do that all the time as well :D
Great video, however in JavaFX 20 you don't need all the files in the bin folder to be included. You only need - glass . dll, javafx_font . dll and prism_d3d . dll if you just have a basic FXML JavaFX application with the 4 main modules (javafx . base, javafx . controls, javafx . graphics and javafx . fxml). If you use more modules you might need more dll dependancies ofc
Thank you very much for letting us know. The beauty of software is that it keeps evolving.
Sir, I did all the steps but the jar file won't to start or launch .... I have : jdk-17.0.2 and jdk-18.0.1.1 and javafx-sdk-18.0.1.
the problem is in Eclipse and Intellij ..... just on javafx but for just java there is no problem.
I worked on Swing on Eclipse and the jar file work correctly .... I don't know why in javafx nothing work when I export but and compilation it work well ??!
Straight to the point and concise, Thank you so much man!
Glad to hear it was helpful!
You should do a follow up video on this but with maven and not just JavaFX but any possible dependency
That is a pretty good idea I might do that! :)
Check out my newest video it should be what you are looking for:
Create executable jar file for JavaFX 15 using Maven: ua-cam.com/video/EyYb0GmtEX4/v-deo.html
Oh my god.. such a simple fix.. Thank you, you saved my sunday.. :)
Happy to help
Even though this video is old it helped me a lot!
I just want to leave that comment here to say thank you!
God bless you sir! It actually worked thank you so much :)
Glad it helped
Thank you, I've been trying to figure out why it wasn't taking the jxml file and went through 2 ide's to try and solve this.
This does not work for me.
I just have: A Java Exception has occurred.
I can run it with "java -jar test.jar" though.
have you done it
Thank you so much, my friend! I have spend the whole evening, trying to figure out, what am I doing wrong and now I see this video! Sry for my bad english...
Glad I could help!
Thank you so much. I have been stuck on this for days.
Glad I could help!
THANK YOU so much for this! IntelliJ really does not make this an easy process.
Glad you found this helpful.
2:07 where can I download those JavaFX folders? I don't have them and can't seem to find a download link anywhere. I have version 19. On gluonhq There are no .dll files or bin folder for version 19.
I rarely comment but your video helped me a lot thanks 💯
I am very grateful for your comment and glad to hear my video was good enough to deserve one of your rare comments!
Thanks you, it's very helpful !. For those who encounter the error: "Error: JavaFX runtime components are missing, and are required to run this application when export .jar file" when run .jar file with command: "java -jar app.jar". Let's add dependencies in pom.xml:
org.openjfx
javafx-base
12
org.openjfx
javafx-controls
12
org.openjfx
javafx-graphics
12
win
org.openjfx
javafx-fxml
12
org.openjfx
javafx-web
12
org.openjfx
javafx-media
12
org.openjfx
javafx-swing
12
TNX SO MUCH
I was stuck at first part myself
Glad it helped! :D
Hey, I'm trying to do the same but on Mac OS. I mean I want to build artefacts on Mac OS but I want to run a program in Windows 10. Unfortunately it does not works. The only way I can run a program on windows is use cmd and "java --module-path path/to/fx/lib --add-modules JavaFX.controls, JavaFX.fxml - jar app.jar". I added all DLL's but this does not works :(
I am not a Mac OS user and have never been, so I have no idea why it doesn't work. Hope you figure it out! :)
@s3nsi milla,
I can see you posted another comment but for some reason it is not showing.
But regarding your qustion, I am using JavaFX JDK 15 in this video.
Thank YOu!!!!!!!!!!!!!!!! After all the videos on youtube, this is the only method that works! thank you so much!
Glad it helped!!!!!
Tysm! What a nightmare trying to figure this out. I followed other tutorials but it had to be all of these steps for it to work. I wonder why it doesn't like the "extends Application" in main part...? Thx again!
I am actually not 100% sure. I struggled to get things working, found some random article providing this solution, and then didn't ask any questions. But I would assume there are some hardcoded starting points somewhere causing issues, but that is just my guess.
So when I click on jar file , nothing really happens
Not all heroes wear capes. No but seriously, thank you so much! I was about to rip my hair out, and I'm bald.. so like, that wouldn't have went well!
I know the feeling! I also struggled getting this working and just wanted to share what I found, but this sadly do not work for everyone.
Thankyou very much for making this video. ✨
Glad it was helpful!
Help me!
I'm trying to build jar file from lesson #17: FileChooser: saving files, but it doesn't work.
could someone explain to me why?
By the way, thank Random code for this great course! really appreciate your work.
It worked thank you so much was stucked here from days .Just one doubt how you selected all files at once from bin?
I selected all the files by first clicking on the first file then holding down shift and clicking on the last files, then all files in between will also be selected (I use Windows btw).
Well-explained and functional, this gem really helped me out!
That is so great to hear! These videos are getting a bit older, but good to hear they can still be valuable.
Thank you for the video! I am just starting to learn Java. Please tell me, this jar file does not require anything other than JVM? Are all required libraries packed into a jar file?
If the jar file was created with all of its dependencies included, then it should not require any other libraries or dependencies to run other than the JVM. However, if the jar file was created without including all of its dependencies, then it may require other libraries or dependencies to be available on the system to run.
In most cases, we can create what is called a fat jar to include all needed dependencies.
@@Randomcode_0 Thanks a lot!
Maybe someone runs in to the same problem as me: this didn’t work with java 18 (Oracle OpenJDK version 18.0.1), but it did work with java 17 (Oracle OpenJDK version 17.0.1)
For some reason, most "tricks" only seem to work for some versions. Which is a bit annoying.
Thanks dude. You really helped me
Glad to hear it!
i don't know how to thank you man
and i don't know why the other tutorial didn't mention these steps
can you please explain what you have done in this video and why you added those files from javaFx sdk ??
and thanks again
I am glad I could help!
JavaFX used to be a part of basic Java, however, it was removed from Java 11, we, therefore, need to manually add all the JavaFX functionality to our projects. What we are doing is simply adding java code we can then reference and use like a button or a text field.
@@Randomcode_0 thank you so much man I really appreciate your help
i spent a lot of time looking for a solution
Hi!
What do you think about to make a video for Kotlin TornadoFx project import to jar with IntelliJ and with gradle? I only found written examples on Stackoverflow and none of them works for me. Thanks in advance!
Thanks!!! It works fine :)
Can you maybe explain why you need to get all the files from the bin folder?
Glad I could help!
We need to get the files from the bin folder because we are creating a normal jar file (Not including JavaFX), we then manually need to get the JavaFX files into the jar file to get it working with JavaFX (the bin folder contains all the JavaFX classes). We cannot just create a JavaFX Jar file because the newer versions of JavaFX have some problems.
Hope this explains it :)
@@Randomcode_0 Thank you for your answer ! :)
Could you tell me the source where this is explained or documented? I can't find any usefull explanation on IntelliJ or JavaFX (openjfx-docs).
@e s This way of doing it is not a "proper" way, and I doubt any real documentation exists, at least not that I know of. This is just a way it worked for me in the past, I am sorry I cannot give you a better answer :)
@@Randomcode_0 Thank you anyway for your efforts mate :)
is there a way to make the file smaller? 41mb for a small program like that is a little big
This works for a simple program with no additional libraries. My program uses additional libraries such as Lucene for text searching and Java mail for sending messages. My program reads a file at startup as well. Error: Could not find or load main class main.AncestryLaunch
Caused by: java.lang.ClassNotFoundException: main.AncestryLaunch
You are very much right, this is a very manual apraoch only working for JavaFX. Building larger and more complex project you should always use a build tool like maven or gradle.
Thank you for your video, helps me a lot. Nevertheless mi application doesn´t find the files (words, html, database) needed to work propertly. It´s seem that all the paths are wrong. I checked the jar file and have the same structure than my proyect, and in IntelliJ it´s work perfect. Any Idea why it´s happening??
You would need your files to have a relative path, which can be used by the project. This means you should place any file you interact with in the resource folder and retrieve them as if they were located there. If this is not the issue, I am not quite sure.
hi: please tell us ; maven or gradl used in this project? thanks a lot
In this video I am neither, it is a plain Java application where I manually added JavaFX. I would recommend using Maven.
I followed your way and everything worked great beside the init() and stop() methods... is there a way to make them work as normal? or maybe some workaround? I am getting really hard time with it.
does maven or gradle will have anything affecting the steps you mentioned?
Gradle is built on Maven so I would assume it should be possible to achieve the same result with both, however I am not too familiar with Gradle so I can't say for sure.
Hi
i did everything exactly the same but the built jar file is not opening not giving even an error, However i built a swing GUI app it works.
i have this problem only in JavaFX project.
I am sorry I got no idea why it does not work, and it is very weird it is not giving any errors. The problem regarding JavaFX is that it is no longer supported by the newer versions of Java.
This tutorial has been helpful to me, thanks a lot.
Glad it helped!
God bless you and thank you! You literally saved me
Glad I could help!
please i have afile jar created with java 17 and i want to convert it or make it work with java 1.8 . how ican do it
Thanks soooooo much!!! It really helped me a lot. Great work :D
Glad to hear I was able to help!
when i run the artifacts which I built, the image and txt file can't be loaded. it said "path" (The system cannot find the path specified). but if I run on intelliJ, it completely normal. I dont understand why. Can u explain it for me
I would assume it is because you access your files using a relative path or the full, path which would be changed when you build you program. You should put text and images inside a resource folder, you then need to access your files through the resource folder, which will stay the same when you build you project.
I got a video about this topic: ua-cam.com/video/ABXiJkCcevc/v-deo.html
@@Randomcode_0 i do exactly the same as you but i still get "Cannot invoke "java.net.URL.getPath()" because the return value of "java.lang.Class.getResource(String)" is null". In my resources i have 1 package, i have put my txt file inside it and even outside that package (but still in resource). If i just create a java project then do like you is ok but with javaFX i dont understand why
@@Randomcode_0 sorry my mistake :))) i dont know why when i use in class which is not main although i have add "Main.class" before getResource it didnt run but in Main file it run perfectly. Anyway tks you very much
Glad I could help :)
One question, when I make a Main_1 class do I need to add every external libs I use or only JavaFX?
We do it with JavaFX because it is no longer supported by newer versions of Java, it should not be necessary to add every library, but it depends on the library. I sadly cannot give you a real answer, because it depends, we need to add everything that is not supported by the JDK we use.
@@Randomcode_0 Oh yes, I forgot they parted JavaFX from Java in the newer version, ok I'll try the good ol' brute force when the time comes for executable build :D
That's the spirit! :D
Thanks Sir but i have observed that when u have different package and u build its does not run. When is it appropriate to build jar file when the project is completed or as you are developing or at the initial stage
I am not 100% sure when it is "correct" to use jar files. You should think of a jar file kind of like the ZIP file format, which means we use to compress a project into one file which we can then send to other to reduce loss of data.
Takle a look at the Java Documentation for more information: docs.oracle.com/javase/8/docs/technotes/guides/jar/jarGuide.html
I create jar using uaing this video.but i converting it into exe using launch4j get error as jni error occured.problem is in my jre.how to fix that.please help dear.
Thank you it helped me.
Glad it helped
if i deploy it in vercel will the link i get from it be able to work as it does when i execute in IntelliJ?
Thanks for the video! When I launch the jar nothing happens and when I look at the error message it gives me
"Error: Could not find or load main class com.traptricker.etherminetrackerjavafx.Main_1
Caused by: java.lang.ClassNotFoundException: com.traptricker.etherminetrackerjavafx.Main_1".
Do you know how I fix this?
it doesn't work for me.
my JDK version is 16 and OpenJFX 17.
I guess there some bugs to be fixed in my version.
or i have some configuration errors or it is all about the version I've been used.
Thank you very much after sir after a long time of googling ,this is a brilliant solution .
Glad you found this helpful!
This is brilliant, thanks so much! I've tried it out with a simple JavaFX project and can now run it from my terminal, no IDE needed.
One quick q - if I have a project that reads from / writes to a .txt file how can I include that in the build please?
I am not sure how it would work if you have a file in your resource folder and then just read and write to it using the resource folder as the destination you need to use in your jar. As far as I understand this should still work in a JAR, but I could be wrong. In larger projects, you would connect your project to a database, which is an entirely different world of its own.
@@Randomcode_0 ace, thanks for this, I'll give it a go.
thank you bro, you helped me a lot
Thank you! Glad you enjoy my content :)
In bin folder I am unable to copy all the files...can someone help me out plzz
Inside my bin folder I click on the first file then hold down shift and press on the last file, and then I just click ok to import the files.
Hello. Can you possibly do the same with Eclipse instead?
I do not have any experience working with Eclipse and therefore does not plan to make any video about it any time soon.
Any reason why mine would be exporting as a zip?
I am on Linux so when I downloaded the sdk, there was no bin folder. Do I have to download the one for windows and use the dlls from there?
I have not been able to find a proper solution to your problem. My best suggestion would be to use something like Maven or Gradle to try building you Jar file.
@@Randomcode_0 downloading the windows dll files worked
Nice, good to knwo!
Just add the .so files from the bin folder. Most of them start with "lib" but aside from that, the filenames are the same. (You'll be missing some "api-****.dll" files but that's fine, you don't need those on linux)
why i can run the file?
it says a java exception has occured
Got mimes to work, finally ❤
what about javafx application using maven
Check this video for my solution using maven: ua-cam.com/video/EyYb0GmtEX4/v-deo.html
Y este .jar se puede distribuir multiplataforma?
I constantly get this Error: A JNI error has occured, please check your installation and try again. Although I can run my program in Intellij normally. Any clues?
Cheers!
I have never had this problem myself, after reading a bit about you error message, it seems to be a problem regarding your java version on your computer.
Found this page trying to solve the problem: webdeasy.de/en/error-a-jni-error-has-occured-how-to-fix-this-java-error/
Hope it helped I sadly cannot give any better solution :)
@@Randomcode_0 unfortunately didn't work. Thnx for ur help though! :)
I am sorry I could not be to much help, I am sure you will figure it out!
Have you managed to fix this error yet? I am getting the same thing
@@simonhutchinson2723 I managed to fix this error, I followed the link above and I was using OpenJ9, once I changed it to the correct javaw.exe I checked that my JRE/JDK and SDK where the same. They weren't my java was 1.8.0 and my SDK was openjdk 15, once i switched my SDK to 1.8 after a rebuild of the project it finaly worked. I hope I wasn't too late to help if it helps at all :)
Beautiful, a real big thanks, sincerely !
Thank you so much! I'm glad you enjoyed the tutorial.
i tried run the jar with "java -jar example.jar" but it says "Error: Could not find or load main class Main_1" how to fix this bro?
There are quite a few reasons you could get this error. The simplest solution would be that you have the Main_1 class in the wrong package, it needs to be in src. You could also try removing the underscore from the name because it sometimes is a problem with some operating systems. If this isn’t the case, I do not know why it is not working.
@@Randomcode_0 i created and new project and it runs smoothly, my bad sir. I think my project is broken because i changed the jdk. Thankyou very much :D
EDIT:
After some research about Could not find or load main class error. In my case, this is because sql server driver 9.2. Tried to remove it and it works or downgrading the sql server driver.
Glad you got it working :) And you always learn something when you get it working at the end!
Doesn't work on Linux or Mac because of the missing DLL Files. They are only available on Windows
Good to know :)
does it work on mac or linux too? the one that imports the dlls file, in my experience, DLL associates with windows
I have only tested it on windows. I seem to remember some previous comments discussing that it was possible, but I can't guarantee that it works.
@@Randomcode_0 I tried it, instead of dlls, in mac lib folder i have .jar, .dylib, as well as .properties file, i just put all those to the project and run just fine.
This helps me a lot.
Glad I could help.
Thank you so much. But I meet the problem [Exception in thread "main" java.lang.StackOverflowError]. How can I solve the problem?
A StackOverflowError is a runtime error in java. It is thrown when the amount of memory allocated is exceeded. A common case of a StackOverflowError being thrown, is when call stack exceeds due to excessive, deep or infinite recursion.
Thanks a lot! I've solved my problem. I wrote the wrong code in Main_1.java. I fix the code, and now I run successfully!
when I want to run it i get JNI error. what jre version do you use?
I am using 15.0.1
It is a problem where the Java versions in your program does not exist on your computer.
I had a friend who had the JNI problem as well, he need Java SE Development Kit 15.0.1 downloaded to run the versions build with 15.0.1.
Where to download Java Development Kits www.oracle.com/java/technologies/javase/jdk15-archive-downloads.html
I also had someone else having the same problem using this: webdeasy.de/en/error-a-jni-error-has-occured-how-to-fix-this-java-error/
This method worked for me, the other method from your other video didn't
Good to hear! Some versions of JavaFX just work and some do not. It is a bit weird. I am just glad you got it working.
When i start it with command prompt I get this message: no main manifest attribute, in Restoran.jar
Even tho I have manifest.mf file:
Manifest-Version: 1.0
Main-Class: Main_1
Do you know what could be the problem?
It might be because do not define in which package your main class is located. If you main class was located inside com.mypackage it would look like this: "Main-Class: com.mypackage.MyMainClass"
can i do it without .dll files? large .jar size
Thank you you are a life saver.
Happy to help :)
This really helps me