I'm working on an application on JavaFX using IntelliJ and Gradle.
Everything seems to work fine while I'm running the app with Gradle's build
. I'm planning to actually export it as a fat jar, in order for it to be used without the actual gradle build
.
I also don't want to create an artifact using IntelliJ's wizard, because, as far as I know, it just creates it without any dependencies (didn't inform myself too well for that - but that's what I understood from their answers on the forums).
Getting back to building the fat jar with Gradle, this is how my project structure looks like:
My module-info.java
looks like this:
module com.example.yuber {
requires javafx.controls;
requires javafx.fxml;
requires javafx.web;
requires org.controlsfx.controls;
requires com.dlsc.formsfx;
requires validatorfx;
requires org.kordamp.ikonli.javafx;
requires org.kordamp.bootstrapfx.core;
requires eu.hansolo.tilesfx;
requires org.json;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;
requires com.fasterxml.jackson.annotation;
exports com.example.yuber;
exports com.example.yuber.controllers;
exports com.example.yuber.models;
opens com.example.yuber to javafx.fxml;
opens com.example.yuber.controllers to javafx.fxml;
}
(I needed to include all of these. Couldn't even use Jackson Databind after adding it as a Gradle dependency, before doing this step).
Also, the jar
task from build.gradle
looks like this:
jar {
manifest {
attributes 'Main-Class': 'com.example.yuber.Main'
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
But everytime I run the jar
task from Gradle, I receive the following error:
Entry module-info.class is a duplicate but no duplicate handling strategy has been set.
As found in this question, a solution would have been to just include duplicatesStrategy = DuplicatesStrategy.EXCLUDE
in my jar
task. Doing so indeed builds my jar file, although I can't running, and trying to gradle run
my app doesn't do anything but display the error:
Process 'command 'C:\Users\matea\.jdks\corretto-11.0.15\bin\java.exe'' finished with non-zero exit value 1
Also, running the created jar file with java -jar ...
results in another error:
What I also found on this question was to actually mention the name of the modules inside the Add VM options setting in my Project Structure, like that:
--module-path "C:\Users\matea\.jdks\corretto-11.0.15\lib" --add-modules=javafx.controls,javafx.xml
However, this also didn't seem to work.
This is my project info:
Does anyone have any idea on why I can't create such a fat jar? Also, am I right by telling that a you can run such a fat jar using java -jar
, without having JavaFX and the other modules separately installed?