JavaFX App To Runnable JAR, The Easy Way! (Video #1)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up guys 80 squared here with my first tutorial ever so please bear with me um in this little series i'm going to show you how to build package and bundle with the bright jre environment your javafx application so that it's distributable and not a headache so without further ado uh we're gonna need a bunch of things for this but for this first part i'm gonna be using intellij idea and uh you can get it at jetbrains.com idea uh shout out to you jed brains and intellij they've got the most amazing id and um a great support staff and overall great product um except for this part right the packaging and building a javafx application is quite complicated uh we're gonna be following this open jfx document just um if you you get lost just follow these steps it's basically what i'm doing all right so just non-modular with maven javafx and intellij okay so we're going to open intellij idea create a new project i assume you know about maven if you don't check it out i'm not gonna dive too much into it i assume you're stuck somewhere and i'm gonna go a little bit fast just trying to show you the issues you're gonna run in and how to bypass them right so i'm going to build from archetype like i said i'm just following the tutorial i showed you the links are going to be in the description box by the way as well as my donation page for paypal if this uh helped you get unstuck or you know progress in any way just consider a donation anything helps right uh so the name of the app is gonna be test all right it's not it's not like test application it's rather rather long name 80 squared tech if you don't have this just use com.example it's fine here we're going to be building from arc type fxml javafx version is not really important for this tutorial um we're gonna let maven do its thing again if you're not familiar with maven it's a stan it's a way to standardize projects it was released by oracle if i'm not mistaken and uh it's really neat it let it handles everything for us in the dependency section in the plug-ins and whatever it's pretty cool it looks complicated but once you get used to it it's pretty uh pretty fun all right so now that we have a javafx application we are just going to run in to make sure everything is all right here we are so we just got a frame and when you click on the button it switches to another frame and it's a working app what i am going to do today and the reason for this video i am going to make my application dependent on a an external jar right um spring framework i just used this one so by default i'm going to use that one so i'm even imported the jar so now i'm ready to build my app okay so this is our main class all right standard stuff primary controller hey what's up doggy sorry my german shepherd just wants attention um now what i'm going to do is as i said i'm going to make myself dependent on a third party i know this is not you know very important or you know standard stuff i'm not a professional i'm an amateur so if you've got you know comments about the way i'm doing things this is not the point right this is just tricky to help people uh be crypt dot oh i need imported so import org dot spring frame work dot security dot everything in there and i'm just adding the required line all right so now that we got the library um yeah we're just going to hash a simple string password and generate assault so essentially now straight encrypted dear god i am so sorry all right so now we have a string that is encrypted and we're using an external jar and we're just going to print the password when we click the button so whatever it's really not important i'm just making my app dependent on an external jar and it's going to print the line here so now we got yeah whatever an application that uses an external jar so there's this thing in javafx uh in this version at least called jlink and it was supposed to help you bundle an app and take care of everything for you but i've never gotten into work and it's probably the reason you're here today right so it throws the error and it says that it cannot be used with the um the external jar you're using because of um automatic module because it's basically missing the module info in your in the external jar you're trying to use so it can't use it so it's one of the issues you're going to run into when you're trying to bundle a javafx app so here's what you can do to bypass that right you can try to build a javafx application from module test application but this way i've never gotten into work either there's always something missing like the javafx libraries it's gonna throw a bunch of errors it's it's just a headache so here's a way you can easily bypass all of that you're just going to have to create a java class called launcher right create a main method and in the main method just launch the main method from the other the other class the app class and since this one extends the application interface i don't even know if it's interface but since it extends this and this is a javafx class it's you can't you can't build from a jar from it but since we've created a class called launcher and this one launches the other class we can now create an artifact a jar from module with dependencies and this is going to bundle everything we need even the javafx library so create from launcher not your javafx main class but your java main class and this is going to bundle every javafx library that you're using as well as the external jars you're dependent on and when you build the artifact sorry about that i'm a little bit on the weather now you've got a runnable jar right we're just going to show this in the full the explorer all right it's right here i am going to cut this and on the desktop i created two folders test app and test app installer um so i'm just going to paste it here so it's in here okay just for ease of access so from the command line this is a runnable jar that contains the javafx library libraries sorry that you're using so if you want to run this you got the standard command now you're not forced to tell the java you're using what libraries to use like add modules and whatnot this way you can simply say java jar test application.jar and when you press enter it should run right but you're gonna run into another issue oh i'm not even the right folder sorry cd desktop application dear god sorry about this desktop uh test app sorry cd test app so now i'm in the right folder okay so java jar test application dot jar so now you're running into another issue there's no main manifest attribute in your jar but wait a minute when we created the artifact it created the folder meta inf right with the manifest in it and if you open the file it contains your main class it's a two-line code it's really nothing but copy this line uh go back to explorer use winrar okay that's what i use and it's the only way i know how to do it so open it with winrar sorry if it's in french uh go to the manifest open it with block node note block notepad whatever and you can see here automatic module name empty just replace this line with what you copied your main class from your app save this now it's asking you do you want to update the library so say yeah the archive sorry close winrar and if you run it again now you got a runnable jar but from the command line who wants that really if you're building a javafx application i assume you want to you know release it give it to people so you can use it on their computers right but this is no way to run an app and it's dependent on the fact that the person that wants to run your app has the right jre the runtime environment that you use to create this and it's really a headache so what you can do is wrap it wrap your runnable jar in inside a dot exe file containing the right runtime environment and that's exactly what i am going to show you in my next video so uh stay tuned hope this helps hope you got unstuck and if this helps in any way consider a donation i'll see you in the next video
Info
Channel: AD2
Views: 2,278
Rating: undefined out of 5
Keywords: javafx, java, intellij, maven, jetbrains, deploy, runnable, jar, application, coding, howtoconvertjartoexe, howtodeployjar, jartoexe
Id: IoPXzopsmpE
Channel Id: undefined
Length: 12min 31sec (751 seconds)
Published: Tue Dec 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.