0

I've tried everything by now, so I hope someone in here can tell me more...

Im trying to produce an executable .jar from a IntelliJ Gradle JavaFX project. I used the standard setup that IntelliJ provided, I changed the Gradle.build file however.
The new file I got from here: Non-Modular Gradle (openjfx.io)

I have a main class that has some basic code in it and a launcher class that does not extend Application and is specified as the Main class in the jar manifest. For now I only use javafx.controls and basically everything is as the example they provided here.

When doing the ./gradlew jar command I get the error:

no module-info.java found

Which - as I understand - is not required if I use the Non-Modular approach? However if I add it I get the error:

Entry module-info.class is a duplicate but no duplicate handling strategy has been set.

I tried every other option out there, all of them lead to either the 2. error or the jar was produced but not executable due to the fact that it can't find the Application class... Any help is greatly appreciated.

I just want to point out that I've never really used Gradle before and have never formally learned any coding, but can fiddle my way around usually.

For the sake if it my build file:

plugins {
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.9' // this is old right?
}

repositories {
    mavenCentral()
}

dependencies {
    /* uncomment for cross-platform jar: */
    runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:win"
    runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:linux"
    runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:mac"
}

javafx {
    version = "16"
    modules = [ 'javafx.controls' ]
}

mainClassName = 'main.class.with.Code'

jar {
    manifest {
        attributes 'Main-Class': 'main.class.with.Launcher'
    }
    from {
        // this is what causes the module duplicate error I think (at least it did in my other tries)
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}
mycf
  • 1
  • 1
  • 1
    Did you try https://github.com/dlemmermann/JPackageScriptFX? – CrazyCoder Sep 28 '21 at 16:07
  • This is unrelated to your question, so please feel free to ignore it. If you haven't used Gradle before, my advice is to used Maven, it is easier in my opinion. Note that is just my opinion, others may differ. Gradle likely works better when you really need to do stuff that isn't handled by standard Maven conventions and plugins, but if you are just starting out with build systems and aren't doing anything non-standard, I think Maven is simpler and is better supported by Idea. – jewelsea Sep 28 '21 at 16:27
  • Related to your question, I do not think you should use the approach you are using (trying to create a fat jar in which JavaFX runs off the classpath rather than the module path), [this answer explains why and discusses alternatives](https://stackoverflow.com/questions/68818710/multi-module-javafx-maven-project-packaging-issue/68823040#68823040). Every second day there is a question of somebody trying to create a fat jar with JavaFX on the classpath and failing. Even if they get it to work, it isn't a supported runtime config. – jewelsea Sep 28 '21 at 16:30
  • Thank you! I naively thought, that if I create a java project I can compile it into a jar, containing also the dependencies and then distribute it. Thats why I've chosen java in the first place... Turns out its not that simple... I will look through your linked answer, thank you. @jewelsea – mycf Sep 28 '21 at 16:40
  • I think the confusion here is understandable. I don't think openjfx.io should be documenting how to create a jar file which results in attempts to run JavaFX in an unsupported configuration. – jewelsea Sep 28 '21 at 16:47
  • 1
    Which brings us back to the first answer by @CrazyCoder. It is for non-modular Maven projects and shows how JavaFX applications should be packaged and distributed today. NOT as fat jars! – mipa Sep 28 '21 at 17:09

0 Answers0