What is causing this "jpackage does not exist" error? - java

I'm trying to make an installer from my Gradle + JavaFX project using jpackage but the following error occurs:
Execution failed for task ':jpackageImage'.
> /home/jonander/.gradle/daemon/6.8/null/bin/jpackage does not exist.
This is my module.info:
module Seftic.main {
requires java.sql;
requires javafx.base;
requires javafx.controls;
requires javafx.fxml;
}
This is my configuration in build.gradle:
plugins {
id 'java'
id 'org.beryx.jlink' version '2.24.1'
id 'org.openjfx.javafxplugin' version '0.0.10'
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml','javafx.base' ]
}
What is causing this error, and how can it be fixed?

Don't know if anyone found a better solution but, you could set jpackageHome to your JDK install, in your build.gradle:
jlink {
jpackage {
jpackageHome = '/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home'
installerType = 'dmg'
}
}

Related

Gradle JavaFX Jlink : duplicate module on application module path

I have a project working with gradle and everything build and run perfectly but I have issues packaging my application. I work on WSL and would like to have both linux and windows executables but to begin having one is okay I don't really care as long as it works and I can understand how to replicate it on the other OS.
So far, I have read a lot of things on the internet and tried to use this plugin in order to package my application. But when I use gradle jlink, I am warned about a duplicate module issue as you can see below. I have tried many things but cannot find anythign which works or a similar problem on the web. Would you have any clue on what I may be overlooking because of my inexperience?
Thank you in advance !
Starting a Gradle Daemon, 31 busy and 1 incompatible and 12 stopped Daemons could not be reused, use --status for details
> Configure project :
Project : => 'CharacterCreator' Java module
> Task :createMergedModule
error: duplicate module on application module path
module in javafx.base
error: duplicate module on application module path
module in javafx.controls
2 errors
> Task :createMergedModule FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':createMergedModule'.
> Process 'command '/opt/graalvm-svm-java11-linux-gluon-22.1.0.1-Final/bin/javac'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 42m 15s
5 actionable tasks: 3 executed, 2 up-to-date
Here is my gradle.build file :
plugins {
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.16.2'
}
repositories {
mavenCentral()
mavenLocal()
}
javafx {
version = "19"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
dependencies {
implementation "org.aerofx:aerofx:0.2"
implementation "pdfbox:pdfbox:0.7.3"
implementation "org.javatuples:javatuples:1.2"
implementation "org.controlsfx:controlsfx:11.0.3"
implementation "org.mariadb.jdbc:mariadb-java-client:2.1.2"
implementation "io.gitlab.vincent-lambert:miscellaneousWidgets:1.7"
implementation "org.apache.httpcomponents:httpclient:4.5.13"
implementation "org.apache.httpcomponents:httpmime:4.3.1"
}
application {
mainModule = 'CharacterCreator'
mainClass = 'CharacterCreator.Menu.App'
}
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked'
options.deprecation = true
}
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher{
name = 'hello'
jvmArgs = ['-Dlog4j.configurationFile=./log4j2.xml']
}
}
And my module-info file :
module CharacterCreator {
requires aerofx;
requires javafx.fxml;
requires pdfbox;
requires javatuples;
requires java.sql;
requires javafx.base;
requires javafx.graphics;
requires javafx.controls;
requires org.controlsfx.controls;
requires mariadb.java.client;
requires miscellaneousWidgets;
requires java.desktop;
requires java.net.http;
requires httpmime;
opens CharacterCreator.Creator to javafx.fxml;
exports CharacterCreator.Creator;
opens CharacterCreator.Edits to javafx.fxml;
exports CharacterCreator.Edits;
opens CharacterCreator.Menu to javafx.fxml;
exports CharacterCreator.Menu;
opens CharacterCreator.Misc to javafx.fxml;
exports CharacterCreator.Misc;
opens CharacterCreator.Races to javafx.fxml;
exports CharacterCreator.Races;
opens CharacterCreator.Relations to javafx.fxml;
exports CharacterCreator.Relations;
opens CharacterCreator.Visus to javafx.fxml;
exports CharacterCreator.Visus;
}
I had the same problem, and I found out, that the folder build/jlinkbase/jlinkjars contained mentioned modules for both platform - mac (which I use to develop) and win.
after reading https://github.com/openjfx/javafx-gradle-plugin/issues/65 I just needed to identify the "polluting" library and applied the fix, which was mentioned:
implementation (....) { exclude group:org.openjfx }

Launch4j exe crashed silently or can't execute

Running the compiled executable jar with java --module-path {$SDK_PATH} add-modules javafx.controls, javafx.fxml, javafx.media -jar frogger.jar is fine. However, executing the compiled exe from launch4j will not run or crashed silently I would say. Is there anything that I'm doing wrong here? Is there any way to see the error?
I've copied and pasted the unzipped jre in bundled directory. So I'm guessing the issue is either my launch4j configuration in build.gradle is wrong or the jre version is wrong.
the jre that I pasted in is AdoptOpenJDK windows x64 jdk-15.0.1+9
plugins {
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.9'
id 'application'
id 'edu.sc.seis.launch4j' version '2.4.9'
}
group 'com.tsb'
version '1.0'
mainClassName = 'com.tsb.frogger.core.Launcher'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'junit:junit:4.12'
}
javafx {
version = '15'
modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.media']
}
task myJavadocs(type: Javadoc) {
source = sourceSets.main.allJava
}
jar {
manifest {
attributes "Main-Class": "$mainClassName"
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
launch4j {
// headerType = "console"
mainClassName = "$mainClassName"
icon = "${projectDir}/icons/frogger.ico"
bundledJrePath = "jre"
bundledJre64Bit = true
}
Rather than using launch4j, I recommend that you take a look at jpackage, which is available in JDK 14 and 15. See Packaging Tool User's Guide. Note that for Windows you will also need to download the WiX toolset.

Error: module not found: org.controlsfx.controls

At first I am a beginner in the module system of Java... I want to connect org.controlsfx.controls library to my app as module. I've created the next module-info.java in my project:
module yummy {
requires org.controlsfx.controls;
requires javafx.controls;
requires javafx.fxml;
opens com.contedevel.yummy.gui to javafx.fxml;
opens com.contedevel.yummy.control to javafx.fxml;
exports com.contedevel.yummy;
}
And build.gradle:
plugins {
id 'application'
id "org.beryx.jlink" version "2.17.5"
}
group 'com.contedevel'
version '1.0-SNAPSHOT'
application {
mainClassName = 'com.contedevel.yummy.App'
applicationName = 'yummy'
applicationDefaultJvmArgs = [
"--add-opens=javafx.base/com.sun.javafx.runtime=org.controlsfx.controls",
"--add-opens=javafx.base/com.sun.javafx.collections=org.controlsfx.controls",
"--add-opens=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls",
"--add-opens=javafx.graphics/com.sun.javafx.scene=org.controlsfx.controls",
"--add-opens=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls",
"--add-opens=javafx.graphics/javafx.scene=org.controlsfx.controls",
"--add-opens=javafx.controls/com.sun.javafx.scene.control=org.controlsfx.controls",
"--add-opens=javafx.controls/com.sun.javafx.scene.control.behavior=org.controlsfx.controls",
"--add-opens=javafx.controls/javafx.scene.control.skin=org.controlsfx.controls"
]
}
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'yummy'
}
jpackage {
resourceDir = file("$buildDir/resources")
}
}
repositories {
mavenCentral()
}
dependencies {
implementation('org.controlsfx:controlsfx:11.0.1') {
exclude group: 'org.openjfx'
}
compile 'org.webjars:font-awesome:5.13.0'
testCompile 'junit:junit:4.12'
}
But when I launch my app (./gradlew run) I get the error:
yummy/src/main/java/module-info.java:2: error: module not found: org.controlsfx.controls
requires org.controlsfx.controls;
The most interesting is IntelliJ IDEA doesn't show any errors in module-info.java.
How to connect org.controlsfx.controls as module?
P.S. I don't need to connect OpenJFX modules because I use Liberica 14 with built-in OpenJFX

How to force gradle to add dependencies to the module path instead of the class path in eclipse?

I have a gradle javafx library which build.gradle lokks like this :
plugins {
id 'java-library'
id 'java-library-distribution'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
repositories {
mavenCentral()
jcenter()
}
jar {
archiveName = 'streampi-fx'
}
distributions {
main {
distributionBaseName = 'streampi-fx'
contents {
from 'src/main'
}
}
}
javafx {
version = "14"
modules = [ "javafx.controls", "javafx.fxml" ]
}
with a module-info requiring javafx :
module fr.streampi.fx {
exports fr.streampi.fx.view.icons;
exports fr.streampi.fx.model;
exports fr.streampi.fx.model.io;
exports fr.streampi.fx.model.utils;
exports fr.streampi.fx.view;
requires javafx.base;
requires javafx.controls;
requires transitive javafx.graphics;
}
I'm running my project in eclipse but every time I refresh the project, all dependencies are put to the class path instead of the module path. I then have to put them back manually in the module path every time my projects refreshes. How to make gradle set the dependencies in the module path ?
I am using this one in my root build.gradle (with Gradle 6.7)
subprojects {
apply plugin: "java"
java {
modularity.inferModulePath = true
}
repositories {
jcenter()
}
}

Trying to run executable jar of JavaFX app - Error: JavaFX runtime components are missing

I've created a JavaFX 11 app that is ready to be deployed.
I use Gradle 5.0 as my build tool and this command to compile the jar:
jar {
manifest {
attributes(
'Main-Class': 'checkmydigitalfootprint.MainApp'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Then on command line I've tried different commands to run the jar file:
java -jar CheckMyDigitalFootprint.jar
java -jar CheckMyDigitalFootprint.jar --module-path="/users/joseph/eclipse-workspace/javafx-sdk-11.0.1/lib" --add-modules=javafx.controls
java -jar CheckMyDigitalFootprint.jar --module-path="/users/joseph/eclipse-workspace/javafx-sdk-11.0.1/lib" --add-modules=javafx.controls --add-exports=javafx.graphics/com.sun.javafx.util=ALL-UNNAMED --add-exports=javafx.base/com.sun.javafx.reflect=ALL-UNNAMED --add-exports=javafx.base/com.sun.javafx.beans=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.glass.utils=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
But all result in the same error:
Error: JavaFX runtime components are missing, and are required to run this application
Rest of build.gradle:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.5'
id 'eclipse'
}
repositories {
mavenCentral()
}
dependencies {
/* uncomment for cross-platform jar: */
// compile "org.openjfx:javafx-graphics:11:win"
// compile "org.openjfx:javafx-graphics:11:linux"
compile "org.openjfx:javafx-graphics:11:mac"
compile 'com.jfoenix:jfoenix:9.0.8'
compile 'org.json:json:20180813'
compile 'com.google.api-client:google-api-client:1.23.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
compile 'com.google.apis:google-api-services-gmail:v1-rev83-1.23.0'
compile group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.1'
compile 'com.sun.activation:javax.activation:1.2.0'
compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.2'
testCompile "org.testfx:testfx-core:4.0.15-alpha"
testCompile "org.testfx:testfx-junit:4.0.15-alpha"
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
run {
if (osdetector.os == 'windows') {
// Temporal fix for Eclipse with JDK 1.8 and Windows
systemProperty "java.library.path", "C:\tmp"
}
}
jar {
manifest {
attributes(
'Main-Class': 'checkmydigitalfootprint.MainApp'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
mainClassName = 'checkmydigitalfootprint.MainApp'
This is explained on official OpenJFX website
The solution is simple, just add following VM option:
--module-path /path/to/javafx-sdk-11.0.1/lib --add-modules=javafx.controls,javafx.fxml
for your Gradle project apply JavaFX gradle plugin
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.5'
}
add the required modules. e.g:
javafx {
modules = [ 'javafx.controls' ]
}
Specify version of JavaFX
javafx {
version = "11.0.+"
}
Hopefully this will help you :)
You solve the problem by using this
Java -jar --module-path /path/to/javafx-sdk-11.0.1/lib --add-modules=javafx.controls,javafx.fxml (path to your jar file)
I have no experience with Gradle but was having the same problem with a runnable jar giving the "JavaFX runtime components are missing...". (Using openJDK/JFX 11.) Even when the vm arguments were correctly included in the command line. The problem was the "Library handling" option for building the runnable jar. "Extract required libraries.." didn't do the job. "Package required libraries..." was the correct option for building a runnable jar file with JavaFX dependency.
To also solve this problem.....
You can create another main class aside the main class javafx provided and then call the javafx main class from the main class you created. In this way you can create an executable jar with all the javafx runtime module present and create an installer form the jar. This is mostly applicable when you are using any jdk above 8

Categories