-
Notifications
You must be signed in to change notification settings - Fork 145
Include dependencies in jar #236
Comments
So So a self-contained .jar with OpenJFX seems to be unsupported at the moment? |
I can try later to reproduce, but you are using Java 10, which includes JavaFX, and then adding JavaFX 11 dependencies. That looks like a bad idea. |
The reason is that the Java 11 runtime will check if the main class extends javafx.application.Application, and if that is the case, it strongly requires the javafx platform to be available as a module, and not as a jar for example. While going modular is definitely the way to go, I still think it's unfortunate that JavaFX applications are treated a bit different here from other application (where you can still use the classpath). There are some easy workarounds though. For example, you can have a main class that is not extending javafx.application.Application, and that main class can then call the main(String[]) method on your real main class (that way, the Java launcher doesn't require the javafx libraries to be available as named modules). |
OpenJDK does not include OpenJFX as far as I know?
Thanks, now it works. Next step I need to figure out how to bundle all the native libraries (windows, mac, linux) instead of only one. |
Only from 11. You are using Java 10, which includes JavaFX 10. |
Oracle JDK 10 include JavaFX, OpenJDK 10 does not. I'm using OpenJDK 10. |
Sorry, I quickly saw |
Working example:
src/HelloFX.java
pom.xml
|
We also ran into |
Can't thank you enough @klausenbusk |
Never again. Please. This took way too long to find a tool that would make it. And honestly, it's unlikely I could replicate it if I tried. Nonetheless, here's some avenues to look into if you need it. Gradle, (not Maven) for building the project. I used Gradle for building the project. Because I needed access to shadow (https://github.com/johnrengelman/shadow) to make this happen. shadowjar task builds this almost like magic. More useful URLS: https://stackoverflow.com/questions/53533486/how-to-open-javafx-jar-file-with-jdk-11?noredirect=1 JAR fat vs nonfat javafxports/openjdk-jfx#236 (comment) Why need Launcher class? Below is the build.gradle I used and my build project structure GradeAnalyzer | .gradle | .idea | build | gradle | src | | main | | | java | | | | Controller.java | | | | GradeAnalyzer.java | | | | GUI.java | | | | Launcher.java | | | resources | | | | GUI.fxml | | test | build.gradle | gradlew | gradlew.sh | settings.gradle buildscript { repositories { jcenter() flatDir dirs: "/home/thomas/Downloads/javafx-sdk-14/lib/" } dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0' classpath files("/home/thomas/Downloads/javafx-sdk-14/lib/javafx.controls.jar") classpath files("/home/thomas/Downloads/javafx-sdk-14/lib/javafx.fxml.jar") } } plugins { id 'java' } plugins { id 'application' id 'org.openjfx.javafxplugin' version '0.0.8' } apply plugin: 'java' apply plugin: 'com.github.johnrengelman.shadow' group 'com.utopple.code' version '1.0-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } javafx { version = "13" modules = [ 'javafx.controls' , 'javafx.fxml'] } dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' } mainClassName = 'Launcher'
rather than from app.core.Application see javafxports/openjdk-jfx#236 (comment)
Our main class is not a JavaFX application class, because of our workaround for OpenJFX normally needing to be a module: javafxports/openjdk-jfx#236 This fixes an error about missing JavaFX runtime components when running the shadow jar with Java 14.
Ran into this just now, when running the Non Modular Gradle sample from Intellij on Java 11. The message "Error: JavaFX runtime components are missing, and are required to run this application" sounds like something fundamental is missing from your system. But you can just create another class (which doesn't subclass Application) with a main method which simply calls your Application-class main method - and it then works from Intellij |
Isn't it mentioned in https://openjfx.io/openjfx-docs/?
…On Mon, Jul 27, 2020 at 2:27 PM davidfrancisandroidemul < ***@***.***> wrote:
Ran into this just now, when running the Non Modular Gradle sample from
Intellij on Java 11. The message "Error: JavaFX runtime components are
missing, and are required to run this application" sounds like something
fundamental is missing from your system. But you can just create another
class (which doesn't subclass Application) with a main method which simply
calls your Application-class main method - and it then works from Intellij
You will have people giving up on Java FX because of this issue - I nearly
did myself!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#236 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AI5QOM55UYBVWWYNRXV6O4LR5VQAHANCNFSM4FYWJUHQ>
.
|
@davidfrancisandroidemul Also note that this repo is defunct. The current one is https://github.com/openjdk/jfx. |
The error is indeed mentioned, but in a different section than the one I was following OK will try the new repo, maybe the new examples work? |
I've never had a problem with the instructions, so from my point of view the examples worked and still work. If you have a problem specifically with the examples, file an issue with https://github.com/openjfx/openjfx.github.io, which is the repository for the openjfx.io website. The https://github.com/openjdk/jfx repository is for issues with JavaFX itself. |
…ld file setup by arcostasi in #66: - Move all source code to src/main/java - Move all images to src/main/resources/images - Move all fonts to src/main/resources/fonts - Move main method to CircuitSimRunner since the main class cannot extend Application to be able to run the jar: javafxports/openjdk-jfx#236
The generated jfx distribution requires a wrapper around JfxMain. Main must be the dist's entry point. Renaming JfxMain as Main does not fix the dist runtime problem. See javafxports/openjdk-jfx#236
Hi
I'm trying to include all the (openjfx) dependencies in a fat jar so it can be run without OpenJFX installed. I have successfully built a .jar file contained all the dependencies (I think), but for whatever reason I get:
Error: JavaFX runtime components are missing, and are required to run this application
. I'm not sure if this is a bug or just a lack of knowledge. Either way, I think a working example could be useful.pom.xml (copy
HelloFX.java
tosrc/
)The text was updated successfully, but these errors were encountered: