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

IntelliJ + modular + Gradle does not load resources when running from IntelliJ #34

Open
gerritsangel opened this issue Sep 1, 2019 · 2 comments

Comments

@gerritsangel
Copy link

Hello,

The example for Intellij + modular + Gradle does not start when invoked directly from IntelliJ. It does not find the fxml file here:

    Parent root = FXMLLoader.load(getClass().getResource("scene.fxml"));

and throws a NPE.

Is there a way to fix this with the Gradle setup? Starting the application with gradlew run works, but then I don't have a debugger support and it is not straightforward.
I think the problem is that the resource files are build to a different output directory (build/classes and build/resources), but IntelliJ does not merge the directories.

I've imported the project into IntelliJ on Windows 7, set JDK 12 as the Gradle and the Project SDK, but did not do any other changes.

@jperedadnr
Copy link
Collaborator

This is an issue with IntelliJ "default" configuration and how your project is configured as a "gradle" project.

Even if you don't set any VM arguments, IntelliJ will apply them for you. If you have a modular app, it puts everything in the module-path, and that's ok, but misses to add a required --patch-module: your resources and your Java classes are under the same package name but in different folders. That will leads to a "split-package" problem.

Therefore, the JavaFX gradle plugin adds this patch, and solves the issue, but this works only if you run a Gradle task (./gradlew run).

If you run from IntelliJ you will either have to:

  • run from the Gradle window, tasks -> application -> run.
  • or, merge source code and resources
  • or edit the run configuration, and add something like --patch-module hellofx=/path/to/resources

@alexspurling
Copy link

alexspurling commented Mar 17, 2021

@jperedadnr Could you provide some more detailed instructions on how to get the sample applications to work in IntelliJ? You say "edit the run configuration" - which part of the configuration exactly? Also, what should I replace "hellofx" in your example with? What does this represent exactly? Also, what should I place in "/path/to/resources" as this is obviously not a real path. Again, what does this represent exactly? Finally, could you please point to any kind of documentation either specific to JavaFX or to Java in general where this might already be explained in more detail.

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

3 participants