Search code examples
javagithubjavafx

Uploading a JavaFX project to GitHub


I am trying to upload a project I made using JavaFX to Github. I don't think uploading the entire project file (including the pom.xml, image, and java files) is enough for my program to compile properly when users download it. How do I ensure that people can run my project properly if they don't have JavaFX downloaded and if JavaFX requires VM arguments? I am new to Maven and Github so can someone explain this to me comprehensively?


Solution

  • A JavaFX app needs some supporting JavaFX libraries. These libraries are currently implemented as OpenJFX, a project cooperatively led by Oracle Corp and Gluon.

    You have two avenues to building a JavaFX app:

    • Including JavaFX libraries as a dependency, specified in your POM.
    • Using a JDK that comes bundled with the JavaFX libraries.

    Which avenue is better is a judgement call to be made by you according to the needs of your own situation.

    In neither case do you upload any JavaFX libraries to your Git repo.

    Including libraries

    You may choose to bundle a copy of the JavaFX/OpenJFX libraries within your app. To do so, specify a dependency in your Maven POM file (or equivalent in Gradle). Maven will then download and install a copy of those libraries within your project.

    Example of a dependency within your POM:

      <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>22.0.2</version>
      </dependency>
    

    Get the current version number from a Maven repository such as this one.

    This info was taken from the documentation for using JavaFX with Maven. Study that for more details.

    When your project builds, Maven will download a copy of those libraries, and then install them within your software artifact, likely a JAR file.

    So you need not include the JavaFX libraries in your Git repo. Just include the <dependency> element within your POM. When the other programmer downloads a copy of your project with that POM, and performs a build, their own Maven installation will then download for them a copy of the JavaFX/OpenJFX libraries to be included within their built app.

    Maven (or Gradle) makes this process easy-peasy. Your IDE (IntelliJ, Eclipse, NetBeans, etc.) likely comes with an installation of Maven or Gradle. If not, you can install one, with SDKMAN! being a nice tool for that.

    JDK bundled with JavaFX

    Alternatively, you may choose a JDK that comes bundled with JavaFX (OpenJFX) libraries.

    At least two vendors offer such editions of their JDK products:

    If you choose to omit the OpenJFX dependencies from your app’s final JAR file, omit that <dependency> element from your POM. We don’t need for Maven to download and install the JavaFX libraries because the necessary libraries are already available to your app via their presence with the JDK.

    Be sure to document for other programmers that you expect them to be using a JDK that comes bundled with the necessary JavaFX/OpenJFX libraries.