javafx-maven-plugin icon indicating copy to clipboard operation
javafx-maven-plugin copied to clipboard

Problems running with javafx:run in a project with cross-platform fat JAR settings

Open lielfr opened this issue 5 years ago • 15 comments

Hi! I'm working on a project where building a cross-platform JAR is required. This is our pom.xml: https://github.com/lielfr/lilach/blob/master/lilach-client/pom.xml

Whenever trying to run it using mvn javafx:run, maven refuses to run it on my Mac. However, when commenting out the linux javafx-graphics dependency it runs properly. Is there any way to get around that? Is it a bug?

Thanks

lielfr avatar Dec 21 '19 17:12 lielfr

You don't need to add classifiers for each platform in order to build your project. Just add which dependencies you need and those that are platform-specific will be automatically referenced.

If you want to develop JavaFX applications using Maven, you don't have to download the JavaFX SDK. Just specify the modules and the versions you want in the pom.xml, the build system will download the required modules, including the native libraries for your platform.

Source: Getting Started with JavaFX

betanzos avatar Jan 15 '20 03:01 betanzos

I got the same issue.

I use maven assembly to create a fat cross-platform jar. The jar is not running OS different from my macOS if i dont include os specific modules, but when i do the plugin wong start using mvn javafx:run

gravgaard avatar Mar 26 '20 17:03 gravgaard

Since JavaFX requires platform-specific libs in order to run your app in different OSs you need to build the fat JAR for each target OS.

The problem here is the classes overlapping if you add manually many OS-specific modules.

So, my advice is: build each os-specific fat JAR from your macOS adding manually OS-specific javafx maven dependency instead generic one.

<!-- use this -->
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-graphics-mac</artifactId>
    <version>14</version>
</dependency>

<!-- instead this -->
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-graphics</artifactId>
    <version>14</version>
</dependency>

betanzos avatar Mar 26 '20 18:03 betanzos

Thanks for you answer, That is what i'm trying to do - Having generic libraries in my dependencies, but when using maven-assembly to package the jar, all the os specific dependencies needs to be available on the classpath. How can i do that i tried with profiling, but it dit not work?

gravgaard avatar Mar 27 '20 07:03 gravgaard

Here are my solution to generate a cross-platform JavaFX app JAR: cross-platform-app-fx.

IMPORTANT! You cannot run the example using this plugin because it use the MODULE_PATH and the maven project is only compatible with CLASS_PATH (more details in repository's README).

betanzos avatar Mar 28 '20 04:03 betanzos

You cannot run the example using this plugin because it use the MODULE_PATH and the maven project is only compatible with CLASS_PATH (more details in repository's README).

I am wrong about the above. The plugin is able to detect if our app is modular and run it in the right way. But javafx:run fail on windows for this app (I developed it in this OS) because it cannot load the DLLs and I don't know why. In linux run without problems.

I am working on this. Wait for updates.

betanzos avatar Mar 29 '20 04:03 betanzos

I have opened an issue (#72) about of the impossibility to run the application using javafx:run and added a PR (#73) that fixes it.

See the issue #72 for more details on the underlying problem.

betanzos avatar Mar 29 '20 19:03 betanzos

Great work. What you did in cross-platform-app-fx with creating a launch class making the application loading the classpath modules is a great hack. I also found this on the internet, but it is good to have a repo illustrating this.

Good with the PR. Any idea when to expect this release?

So for now I am able to run the fat jar generated with maven assembly from any OS - if I include all dependencies as you did in the above repo, but javafx:run does not work, and so does the debug not work. Or am i doing something wrong?

gravgaard avatar Mar 30 '20 10:03 gravgaard

Great work. What you did in cross-platform-app-fx with creating a launch class making the application loading the classpath modules is a great hack. I also found this on the internet, but it is good to have a repo illustrating this.

Thanks a lot

Good with the PR. Any idea when to expect this release?

It has to be approved first and I am not part of the company, so I don't know.

but javafx:run does not work

PR #73 fix that, but we have to wait for it to be included in the next release.

and so does the debug not work. Or am i doing something wrong?

For me debug work fine in IntelliJ IDEA. What are you doing? debug

betanzos avatar Mar 30 '20 17:03 betanzos

Well, I was just using the plugin with run some options i googled: Screenshot 2020-03-31 at 08 26 47 javafx:run@debug.

But from now on i do as you illustrate in your screen dump - simply just run the main class. Stupid enough i dont not think of that.

This actually fixes all my problems (thank you x 1000). But i am not utilizing the javafx-maven-plugin then?

gravgaard avatar Mar 31 '20 06:03 gravgaard

This actually fixes all my problems (thank you x 1000). But i am not utilizing the javafx-maven-plugin then?

My answer is yes. Remember you really don't need the plugin in order to run the app from an IDE, it is useful to do it from terminal.

I've never used debugging from Maven, and I've never really needed it.

betanzos avatar Mar 31 '20 16:03 betanzos

Yea it is usefull for the terminal, and a few of my co-workers swear to Visual Studio. So need to take care.

gravgaard avatar Apr 01 '20 05:04 gravgaard

Ok, I will take a look

betanzos avatar Apr 01 '20 05:04 betanzos

I've came upon the same problem as well. Is this a JavaFX issue or is this a plugin issue?

nnoodle avatar May 29 '23 22:05 nnoodle