I have just started a new project based on AdoptOpenJDK 11 and OpenJavaFX 11.
Before during my development, I used VM Arguments which was not always practical when you pass the project to someone else.
So I started to replace my VM Arguments with the module-info.java file.
VM Arguments before:
--module-path ${PATH_TO_FX} –add-modules javafx.controls,javafx.fxml
--add-opens
javafx.base/com.sun.javafx.runtime=ALL-UNNAMED
--add-opens
javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED
--add-opens
javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED
--add-opens
javafx.base/com.sun.javafx.binding=ALL-UNNAMED
--add-opens
javafx.base/com.sun.javafx.event=ALL-UNNAMED
--add-opens
javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED
--add-opens
javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED
module-info.java file now:
module hellofx {
requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
opens org.openjfx to javafx.fxml;
exports org.openjfx;
}
This is where I have a problem, I managed to replace the tag --module path but I can not find a solution for tags --add-open.
Can someone help me?
Edit 12/09:
Now I have a new error with this two lines in the module-info.java
Duplicate requires entry: javafx.fxml
How I can solve this?
Option A Quick and clean :
Change
module hellofx {
requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
//wrong
opens org.openjfx to javafx.fxml;
//right
opens com.your.package to javafx.fxml, javafx.controls;
exports org.openjfx;
}
Option B (Because building a Jar with javaFX seems to be wierd)
You also can do this with Gradle (because you then can easily build your JavaFX jar without much of a Problem)
You should add the gradle fx Plugin, and define Compile arguments.
When you use Gradle you also don't need to download the openJavaFX library manually.
Here is how your Gradle file should look like
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 'eclipse'
id 'java'
id 'java-library'
id 'application'
// This is very Important!
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.beryx.jlink' version '2.12.0'
}
sourceCompatibility = 11
targetCompatibility = 11
repositories {
jcenter()
mavenCentral()
}
mainClassName="com.your.MainLauncher"
// Use this for the Runtime, to run with the required Modules
javafx {
version = "11"
modules = [ 'javafx.controls', 'javafx.fxml','javafx.graphics']
}
sourceSets {
main.java.srcDir "src/main/java"
main.resources.srcDir "src/main/resources"
}
// Your dependecies
dependencies {
compile group: 'org.openjfx', name: 'javafx', version: '11.0.2'
// JAVA FX dependecy. Important!
// Add your other dependecies
}
// to build the jar
jar {
manifest {
attributes(
'Main-Class': 'com.your.MainLauncher'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
// to "include compile arguments " that replace your VM arguments
compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls,javafx.fxml,javafx.graphics'
]
println options.compilerArgs
}
}
you can run this with gradle but also with eclipse. When you build the jar there are also no VM arguments required. I Hope this will help you.
This does also run out of your IDE(intelliJ / Eclipse) if you have Gradle Support plugins installed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With