Export JavaFX 11, 15 or 17 projects into an executable jar file with IntelliJ [2022]
HTML-код
- Опубликовано: 29 сен 2024
- In this video, I will be showcasing how to create a jar file from JavaFX 11 or above with IntelliJ. I hope you enjoyed this video if you did place leave a like and feel free to ask any questions in the comment section.
(Only works on Windows)
My channel publishes videos regarding programming, software engineering especially Java and JavaFX. If that is what you are looking for then do not hesitate to join me on this journey!
Subscribe to my RUclips channel:
/ @randomcode_0
Helpful links:
How to install Intellij: • How to install Intelli...
How to setup JavaFX with IntelliJ: • How to setup JavaFX 11...
How to create a jar file with maven: • Create executable jar ...
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 don't beleive that creating ANOTHER class will help. such a bruh moment. BUT IT ACTUALLY WORKED. Ty
Bruh!
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.
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 for this! IntelliJ really does not make this an easy process.
Glad you found this helpful.
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!
HOLY DAMN!!! THIS ACTUALLY WORKKKKKKKKKKKKKK!!!!!!!!
I know that feeling! Glad I was able to help.
@@Randomcode_0 Yeah been looking for solutions like this for countless of hours before i seen your video, such an hassle...Thank you so much!!
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?
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.
Thx, it worked
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)
hi....good video...but how to do in linux ? thanks
I have not tried it myself, but as far as I know, it should be more or less the same process on Linux. Let me know how it goes.
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!
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 ? (ಠ﹏ಠ)
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 ??!
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!
So when I click on jar file , nothing really happens
Dosent work for me
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
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! :)
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!
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?
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.
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.
God bless you sir! It actually worked thank you so much :)
Glad it helped
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.
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!
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!
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.
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.
what about javafx application using maven
Check this video for my solution using maven: ruclips.net/video/EyYb0GmtEX4/видео.html
when i do this and double click the jar file nothing at all happens can someone help
really appreciate your work , keep creating this type of videos
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.
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.
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 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"
why i can run the file?
it says a java exception has occured
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!
Any reason why mine would be exporting as a zip?
Doesn't work on Linux or Mac because of the missing DLL Files. They are only available on Windows
Good to know :)
Thank you so much. I have been stuck on this for days.
Glad I could help!
Got mimes to work, finally ❤
can i do it without .dll files? large .jar size
I follow your steps, but when I get this exception, and I've tried everything
Error al inicializar la SessionFactory: java.lang.NullPointerException: Cannot invoke "java.lang.reflect.Method.invoke(Object, Object[])" because "org.glassfish.jaxb.runtime.v2.runtime.reflect.opt.Injector.defineClass" is null
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
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).
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!
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 :)
Y este .jar se puede distribuir multiplataforma?
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! I searched for the solution for a long time, your video helped me!
Glad it helped!
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.
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.
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!
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.
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.
Thank you sooooo much!!! Ive been searching internet for this for so long.
Glad I could help! :)
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
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.
didn't work
you know the solution?
Thankyou very much for making this video. ✨
Glad it was helpful!
Even though this video is old it helped me a lot!
I just want to leave that comment here to say thank you!
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/
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: ruclips.net/video/ABXiJkCcevc/видео.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 :)
is there a way to make the file smaller? 41mb for a small program like that is a little big
What if i have multipage app?
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.
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: ruclips.net/video/EyYb0GmtEX4/видео.html
You saved my ass from banging.....god bless you and your family
Thank you so much!
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
TNX SO MUCH
I was stuck at first part myself
Glad it helped! :D
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.
it didn't work for me ((((((((
Bro thx for the tutorial
Ive been looking for it the whole week but just found old methods
I had the same problem! Glad I could help!
God bless you and thank you! You literally saved me
Glad I could help!
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!
really appreciate your work , keep creating this type of videos
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 :)
Tysm. Not even GPT was explaining this correctly to me.
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 :)
Thanks mr
Most welcome
Thank you it helped me.
Glad it helped
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.
Dont work man.
Sorry to hear that, hope you find another working solution.
@@Randomcode_0 But I cannot understand. I did 1-1 same what you did in video. If I click the jar file , the app doenst open yourself.
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 LOVE YOUUUU REEEEEEEEEEEE
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.
Thanks dude. You really helped me
Glad to hear it!
ur a god.
Straight to the point and concise, Thank you so much man!
Glad to hear it was helpful!
Thank you very very much.....! great....
Glad you liked it!
thanks man, you helped me a lot. I was struggling with this problem for about 4 hours now... Thank you
Glad it helped!
It works :). Plus I subscribe :)
Glad to hear it worked!
Glad you subbed! :)
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 bro, you helped me a lot
Thank you! Glad you enjoy my content :)
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.
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
I love you. Thank you. so. much!
No problem 😊