-3

I haven't found an answer yet fitting a knucklehead such as me, so I'll ask for myself : I'm on macOS 13.1 and I have openJDK 19.0.2 installed already ; how am I supposed to install JavaFX ? The only downloads there just spit out a folder, which I have no idea what to do with.

There are no installation instructions that I could find, the site juste says that "The JavaFX runtime is available as a platform-specific SDK, [and] as a number of jmods" which isn't very useful if you have no idea what a jmod even is. What am I supposed to do ?

I don't know if that makes any difference, but I'm trying to install the runtime part of it I guess. I need to run a thing, not code with the library. I don't even know if there's a difference in the Java world though ?

ice-wind
  • 690
  • 4
  • 20
  • 3
    Have you been through https://openjfx.io/openjfx-docs/? – General Grievance Feb 09 '23 at 18:12
  • @GeneralGrievance Yes and I can't find how to install the thing as a user in there – ice-wind Feb 09 '23 at 18:16
  • Click "I have Java installed". The page should say what to do with that downloaded folder. – General Grievance Feb 09 '23 at 18:19
  • 2
    The [Zulu JDK builds](https://www.azul.com/downloads/?version=java-19-sts&os=macos&package=jdk) have JavaFX built into them, just download the version for your OS. – blacktide Feb 09 '23 at 18:20
  • The thing that might confuse you, is that you don't really need to install anything as such. You just unpack the folder and then run your software with the command line as described in the "I have java" link above. – MTilsted Feb 09 '23 at 18:21
  • `> java --module-path ~/Downloads/javafx-sdk-19.0.2.1/ --add-modules javafx.controls mcaselector-2.1.jar` results in `Error occurred during initialization of boot layer java.lang.module.FindException: Module javafx.controls not found` – ice-wind Feb 09 '23 at 18:22
  • @MTilsted Is there no way to just double click the jar and have it find javafx ? – ice-wind Feb 09 '23 at 18:33
  • *"Is there no way to just double click the jar and have it find javafx ?"* -> yes if you use the **Zulu JDK FX** build recommended by @blacktide. It includes JavaFX in the base Java runtime image, so you can create a jar that you could run which uses JavaFX from the runtime image which will work *as long as you know all of your users are doing the same thing...* – jewelsea Feb 09 '23 at 19:43
  • 2
    StackOverflow is a [site for programming and software development](https://stackoverflow.com/help/on-topic). Questions not related to that are off-topic (e.g. "I need to run a thing, not code with the library"). This, I think, is why you have a mismatch between the answer and comments you received and your expectations. – jewelsea Feb 09 '23 at 23:39
  • To allow double-click execution, you can [create a batch file (windows)](https://stackoverflow.com/a/2879843/1155209) or shell script (Linux or MacOS), that runs the app, then double click the batch file to run. Or you can contact the provider of the app and request they make an installer using something like jpackage. – jewelsea Feb 14 '23 at 04:39

2 Answers2

2

JavaFX is implemented as open-source in the OpenJFX sub-project on the OpenJDK project. OpenJFX is led by the Gluon company, in cooperation with Oracle Corp.

OpenJFX is simply a few libraries, a collection of Java JAR files. You need to obtain a copy of the libraries, and make them available to your app. You can do this in one of three ways:

  • Install a copy of the libraries as part of your app.
  • Install a copy of the libraries in a place that will appear on the Classpath of your app. For example, on macOS: /Library/Java/Extensions.
  • Install a JDK that comes bundled with the libraries. I know of two vendors that make an edition of their JDK products to include the libraries: ZuluFX by Azul Systems, and LibericaFX by BellSoft.

By “install” I mean simply making the JAR files available: (1) download, (2) move to the right folder location. There is no need to run an installer app. There is simply not anything complicated enough about this to require an installer.

The last of those three (a JDK with libraries bundled) is the easiest if you are new to programming.

If you will be doing serious work with Java and JavaFX, I strongly recommend learning to use a dependency management tool such as Apache Maven or Apache Gradle. Such a tool automates the chore of locating, downloading, and installing libraries such as OpenJFX.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
-3

I found how to do it, so here's a guide :

  1. Download the JDK for your java version from JavaFX
  2. Open /Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home
  3. Move everything from the lib and legal folders you downloaded to the respective subfolders where we just opened
  4. Delete jrt-fs.jar
  5. Run your program with java --module-path $JAVA_HOME/lib --add-modules javafx.controls -jar Program_Name_Here.jar

Bonus: If you don't want to have to type out that command every time, run :

echo _JAVA_OPTIONS="--module-path=$JAVA_HOME/lib --add-modules=ALL-MODULE-PATH" >> ~/.bash_profile

in your terminal. The modules will all be loaded by default when running java programs (I have no idea if there are any side effects, I don't understand anything about Java).

Please note that the program still won't work when double-clicking it directly, because of java magic or something.

ice-wind
  • 690
  • 4
  • 20