9

I've created a JavaFX project using IntelliJ, together with Maven. I'm trying to test some system that adds items into an XML file and then parses it and shows me all the items added to the file.

I want to use FasterXML/Jackson for parsing the files. In my pom.xml, I've added the following dependency:

<dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
    <version>2.13.2</version>
</dependency>

(...) and I also loaded the Maven changes from the button provided by IntellJ. I also pressed the Reload all Maven Changes button. The "Dependencies" folder seems to be all okay. I've received no errors or complaints: enter image description here

However, when I'm trying to import some Jackson-related class, such as ObjectMapper, like this:

import com.fasterxml.jackson.databind.ObjectMapper;

(...) I receive such an error: Package 'com.fasterxml.jackson.databind' is declared in module 'com.fasterxml.jackson.databind', but module 'com.example.demo1' does not read it.

This is my project structure:

enter image description here

What could be the problem?

Mario Mateaș
  • 638
  • 7
  • 25

2 Answers2

7

I've managed to fix my problem. In my module-info.java I needed to add the following line of code:

requires com.fasterxml.jackson.databind;

Found something similar in an answer provided to a question on Stack (How to solve package is declared in module, but module does not read it?), although the user who answered said you need to also open the module. Opening the module, though, would result in some other error, but just mentioning it as a requirement should be enough.

Mario Mateaș
  • 638
  • 7
  • 25
0

I had this issue in IntelliJ

For anyone still dealing with this issue, I found that it was due to not exporting the controller to java.fx and java.base in the module-info.java

This is assuming that you're using MVC and have a controller package with all controller classes inside

This was the fix:

exports controller;
opens controller to javafx.fxml;

Also make sure that you add this for the model package in the same file (module-info.java):

opens model to javafx.base;
Adammgerber
  • 265
  • 3
  • 4