0

I am looking for javafx 10 or newer. I currently have javafx-sdk-11 and trying to make my programme a single runnable jar file, but apparently since javafx 11, that option isn't available anymore.

So I have to go to the terminal and type the following line to run it :

java --module-path /path/to/javafx/javafx-sdk-11.0.2 or another/lib --add-modules javafx.controls,javafx.fxml,javafx.graphics,javafx.web -jar /path/to/GUI_Music_Gen.jar

Since I can't find older versions of javafx available for download, I ask for your help. If anybody can help me, let me know. Thanks in advance. Btw, I don't know if this will be an issue for compatibility, but I run macOS X.

j35t3r
  • 1,254
  • 2
  • 19
  • 53
Maxlanglet
  • 11
  • 2
  • JavaFX was **removed in Java 11**. So for "10 or older" you don't need anything. It's in the JDK anyway. – Michael Mar 27 '20 at 19:41
  • See list of releases on GitHub: https://github.com/openjdk/jfx/releases – Basil Bourque Mar 27 '20 at 20:33
  • Related questions: [How to deploy a JavaFX 11 Desktop application with a JRE](https://stackoverflow.com/q/53453212/) | [Running JavaFX application with JDK 11+](https://stackoverflow.com/q/50828975/) | [JDK11/JavaFX: How do I make a fat jar without build/depdency management?](https://stackoverflow.com/q/55300695/) | [Maven Shade JavaFX runtime components are missing](https://stackoverflow.com/q/52653836/) | [JavaFX 11 : Create a jar file with Gradle](https://stackoverflow.com/q/52569724/6395627). – Slaw Mar 27 '20 at 23:07
  • If you're using Java 14 consider the `jpackage` tool. – Slaw Mar 27 '20 at 23:08

1 Answers1

1

I would recommend using dependency management like grade or maven to run JavaFX and Build a working Jar.

I can offer you this build.gradle for a working JavaFX project:


buildscript {
    dependencies {
        classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.7.0'
        classpath 'org.openjfx:javafx:11'

    }
    repositories {
        mavenLocal()
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }

    }
}

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

sourceCompatibility = 11
targetCompatibility = 11
repositories {
    jcenter()
    mavenCentral()
}

// configure here

mainClassName = "your.app.main"

publishing {
    publications {
        mavenAar(MavenPublication) {
            from components.java
            afterEvaluate {
                artifact javadocJar
                artifact sourcesJar
            }
        }
    }
}

javafx {
    version = "11"
    modules = ['javafx.controls', 'javafx.fxml', 'javafx.graphics']
}


sourceSets {
    main.java.srcDir "src/main/java"
    main.resources.srcDir "src/main/resources"
}


dependencies {
    api 'org.apache.commons:commons-math3:3.6.1'
    implementation 'com.google.guava:guava:27.0.1-jre'
    testImplementation 'junit:junit:4.12'
    // use java fx just like a regular dependency :) 
    implementation 'org.openjfx:javafx:11'
    compile group: 'org.openjfx', name: 'javafx', version: '11.0.2'
}

// important Configure your project 
jar {
    manifest {
        attributes(
                'Main-Class': 'your.app.main'
        )

    }
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

compileJava {
    doFirst {
        options.compilerArgs = [
                '--module-path', classpath.asPath,
                '--add-modules', 'javafx.controls,javafx.fxml,javafx.graphics'
        ]
        println options.compilerArgs
    }
}

Just replace "your.project.main" with your actual main class and everything should run fine.

Also it is really important that your Main class does not extend from Application. It should only Launch the Application.

Luxusproblem
  • 1,913
  • 11
  • 23
  • Thank you for your response. I tried using gradel on IntelliJ but stumbled upon an error, something about Java Runtime and class file versions. I tried looking for the solution but couldn't find it. So I think I will try running it through the terminal instead. Can you help me for the file structure ? Plus I don't know if this is relevant but my project depends on an other library, I suppose I need to specify it in my build.gradle file ? – Maxlanglet Mar 28 '20 at 19:30
  • @Maxlanglet Yes you should add that in the dependencies part, also filestructure should be like a regular Java project. Wich Java version are you working with ? Do you use any dependency management like maven ? if not just add a "buil.gradle" file to the root of your project, and remove the *.iml file, wich will be created by IntelliJ. then you should open the gradle menue on the right side of intelliJ and right click on your project and choose "refresh gradle dependencies". How do you import the other library ? – Luxusproblem Mar 28 '20 at 20:13
  • I'm using SDK 13, I tried converting to Maven like I did with Gradel but I just get more and more errors. I tried what you suggested but with no luck, can't build the project, only errors pop up. The other library I imported is jMusic and I downloaded the jar file and added this library via Project Structure -> Librairies – Maxlanglet Mar 28 '20 at 21:58