Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting started tutorial for JavaFX and IntelliJ, modular with Gradle does not work #161

Open
Fataho opened this issue Jul 26, 2020 · 8 comments

Comments

@Fataho
Copy link

Fataho commented Jul 26, 2020

Getting started tutorial for JavaFX and IntelliJ, modular with Gradle does not work
I use java 14 version, 6.5.1 gradle version and IntelliJ 2020.1.4 version

Tutorial can be found here: https://openjfx.io/openjfx-docs/#IDE-Intellij

I repeated exactly every step, except used java 14

Task :run FAILED

Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: /home/fataho/IdeaProjects/hellofx/build/classes/java/main
Caused by: java.lang.module.InvalidModuleDescriptorException: Package hellofx.org.openjfx not found in module

Caused by: java.lang.module.InvalidModuleDescriptorException: Package hellofx.org.openjfx not found in module

Execution failed for task ':run'.
> Process 'command '/usr/java/jdk-14+36/bin/java'' finished with non-zero exit value 1

build.gradle

plugins {
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'org.beryx.jlink' version '2.12.0'
}

repositories {
    mavenCentral()
}

javafx {
    version = "14"
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}

mainClassName = "$moduleName/org.openjfx.MainApp"

jlink {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher {
        name = 'hellofx'
    }
}

module-info.java

module hellofx {
    requires javafx.controls;
    requires javafx.fxml;

    opens org.openjfx to javafx.fxml;
    exports org.openjfx;
}
@AustinHealey1988
Copy link

I have the exact same problem in Eclipse with Gradle.

It begins with multiple errors, which I can reduce by following the advice here: openjfx/samples#40

But, I end up with the same error:

Task :run FAILED
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: C:...\java\main
Caused by: java.lang.module.InvalidModuleDescriptorException: Package hellofx.org.openjfx not found in module

I've searched all over for advice on this exception and haven't been able to find anything that works. The same error is preventing me from getting my own project running, and I'm having difficulty solving it because I set my own project up based on this tutorial.

@Fataho
Copy link
Author

Fataho commented Aug 12, 2020

In the build.gradle I have changed this line
mainClassName = "$moduleName/org.openjfx.MainApp"
into this:
mainClassName = "org.openjfx.MainApp"
Seems to work.

@AustinHealey1988
Copy link

Ok, so when I first tried that, it failed.

However, when I reversed the advice from openjfx/samples#40, which was to rename the resources package from org.openjfx to org.openjfx.hellofx, it finally works!!! I had to refactor the name of the resource package back to org.openjfx.

The strange thing is that when you make this fix and remove "$moduleName" from the mainClassName, Gradle gives the information "No module was provided for main class, assuming the current module. Prefer providing 'mainClassName' in the following format: '$moduleName/a.b.Main'"

So, there is still something I don't understand going on here. But, I'm very glad to at least be able to run this thing, and, therefore, hopefully my project as well.

@Fataho
Copy link
Author

Fataho commented Aug 12, 2020

I agree that this might not be a best fix and it would be great to get a comment from someone that has more knowledge on this.

@AustinHealey1988
Copy link

Ok Fataho, I think I figured it out (at least a small part of it). Based on an issue I saw listed (openjfx/samples#50) which requested updating the example for Gradle 6.4+, I decided to try running this example with different version of Gradle (after spending the bulk of my day prior trying a million other things). If I went back far (Gradle 4, 5, 6), I got all kinds of other errors. But the fact that he specifically mentioned 6.4 led me to try 6.3.

Out of all the versions of Gradle I tried (many), only 6.3 would work for me to run these examples. But, it did work; and it did so with the original line:
mainClassName = "$moduleName/org.openjfx.MainApp"

So, I think our workaround of taking the module name out of that mainClassName is not quite appropriate, though it did work because Gradle was able to guess that the current module is the one with the main class (duh).

I have no idea why Gradle 6.4 plus breaks these examples. But you can easily set your Gradle version back to 6.3 and have things work as intended.

@Fataho
Copy link
Author

Fataho commented Aug 13, 2020

Thanks man, works for me too with 6.3. However it would be also interesting to know how to achieve this with newest versions. Maybe this is a bug, or we maybe now this has to be done differently.

@AustinHealey1988
Copy link

Figured out how to get the example project to work with Gradle 6.6. The Gradle documentation for it is contradictory in places, so it was quite a struggle. Even then, I've still got this showing up for 6.6:

No module was provided for main class, assuming the current module. Prefer providing 'mainClassName' in the following format: '$moduleName/a.b.Main'"

The key is adding the following 2 things:

1-
java {
modularity.inferModulePath.set(true)
}

2-
application {
mainModule = 'hellofx' // name defined in module-info.java
mainClass = 'org.openjfx.MainApp'
}

For number 1, you will see some places in the Gradle documentation that have a different form like the following, which does not work:

java {
modularity.inferModulePath = true
}

Adding those two things gets this project to run with Gradle 6.6. But I still think there is something now quite right. It's hard to say what. It shouldn't be this hard to run the basic example project, that's for sure.

@AustinHealey1988
Copy link

Got it to run without complaints now. It seems sloppy for some reason, but it works fine.

After adding the two things above, the run task was still saying there was no main class identified. I was able to add the code below and get that to go away. Now all tasks run in the project without complaints using Java 14.0.2 and JavaFX 14.

run {
main = "$moduleName/org.openjfx.MainApp"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants