2

I wrote a JavaFX application with JavaFX version 15.0.1.

I'm using IntelliJ IDEA and all is working fine since I execute my code from IntelliJ.

Now I want to deploy the application building the Jar and creating an Executable.

I already know that there are some issues with versions after Java 8 because the packaging is not included anymore.

I searched a lot and found some useful stuff here on StackOverflow and on YouTube, following all the guides step by step.

I also found a video of a guy that uses my same JavaFX version, and IntelliJ to build the Jar, and at the end, he simply double-click on the created Jar and the application runs smoothly and with no errors.

That's my actual setup :

I set up the Launcher.java class to bypass the Main.java problem like in the guides.

package main;

import main.Main;

public class Launcher
{ 
    public static void main(String[] args){Main.main(args);}
}

I built the project and then in artifact I created a new one based on modules and added the .dll files from my JavaFX SDK.

Artifact Setup

After that, I built the project once again, and I went to : Build -> Build Artifacts and Build.

After this process, my out directory seems like this :

Out Directory

And in artifacts -> MenuManager_jar there is my MenuManager.jar file.

MenuManager.jar File

After that, as I saw in the guides, I can simply double click on it, or run it with : java -jar MenuManager.jar, and it should run my application.

But after I double click, nothing happens, even if I run from console, with this command :

java -jar MenuManager.jar

or even

java --module-path "C:\Program Files\Java\javafx-sdk-15.0.1\lib" --add-modules javafx.controls,javafx.fxml -jar MenuManager.jar

it shows this error

Error: Could not find or load main class main.Launcher
Caused by: java.lang.ClassNotFoundException: main.Launcher

So after that, I decided to look for the Launcher.class file myself.

And that is present in my Jar opened as zip :

Jar/main content

Obviously out of the "main" directory in the jar there are all the dependencies/libraries :

Jar Content

I looked for posts/videos/guides/packaging tools, but I can't find a way to create this Jar or Executable for my Project. This process creates the Jar in the right way, but it seems I'm not able to run it for some reason.

I need help with this last step.

jewelsea
  • 150,031
  • 14
  • 366
  • 406
rhagee
  • 126
  • 6
  • 1
    Please [don't upload images of code and error messages](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question). You can edit the question to replace the images with text. – jewelsea Sep 07 '21 at 21:54
  • For building, I recommend using a build tool (e.g. maven or possibly gradle) rather than the artifact manager in the IDE. IDEs have good integration with build tools, so you don't need to run the build tool externally if you don't want to. For distribution, I recommend creating a native installer using [`jpackage`](https://stackoverflow.com/questions/68818710/multi-module-javafx-maven-project-packaging-issue/68823040#68823040) rather than a jar. More info is available in the [runtime images section](https://openjfx.io/openjfx-docs/) of the openjfx docs. – jewelsea Sep 07 '21 at 21:58
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Sep 12 '21 at 07:07
  • To @jewelsea : It's my first post, so I'm not able to put Images in my text. Everytime I try to add one, it says I have to upload it, I will be able to put it in post after I get some interactions with the site I guess. – rhagee Sep 14 '21 at 09:08
  • @rhagee I think you misunderstood. The request was not to include images of text but instead put the text in the question as text. Please see the link I posted. – jewelsea Sep 14 '21 at 09:12
  • @jewelsea Oh yes! Thank you, I'm sorry it's my first post and I didn't know that was a problem doing it. Btw I found out the fix myself! Appreciate your help! Should I fix the post anyway? – rhagee Sep 14 '21 at 09:23
  • If you have time to improve the question in a way that may help others, then do that. Even with an accepted answer, a better written question helps other readers. – jewelsea Sep 14 '21 at 09:33
  • @jewelsea I edited the question, is it fine now? – rhagee Sep 14 '21 at 09:36
  • @rhagee yes, it is much better now. I also inlined the remaining images of the IDE configurations (which are OK to leave as images). I also upvoted your posts which should give you enough reputation to add images to future posts, if needed, in the future. – jewelsea Sep 14 '21 at 19:58

1 Answers1

2

Found out myself the way to fix it!

I had some other external libraries imported in my project over the standard JavaFX jar.

It was a specific mysql library version imported as Jar.

It probably had some problems being built in artifact, I still don't know the reason, maybe it was a version problem or incompatibility.

After replacing it with another Library or removing it, the jar built fine and I'm able to run my appliation even double-clicking.

Suggestions

What I suggest to people with same problem or that want to start a JavaFX application and knows that they are going to create a jar is that :

  • After importing a new Library try to build the artifact so you won't have some suriprises after using it and building.
  • If the library is making the final jar not working, try to replace it with a similar one, or try to find out if there is a different version of the library.
  • Since the start of the project try to build and build artifact every time you make some big changes to be able to track the problem faster.
rhagee
  • 126
  • 6