Reputation: 11
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.
Upvotes: 0
Views: 441
Reputation: 2148
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.
Upvotes: 1