package com.fasterxml.jackson.annotation is not visible
Asked Answered
C

1

5

When I compile my Spring Boot application in Java 9, it fails after a couple of messages such as this one:

package com.fasterxml.jackson.annotation is not visible
    (package com.fasterxml.jackson.annotation is declared in the unnamed module, but module com.fasterxml.jackson.annotation does not read it)

Can someone tell me what is going on here? As I understand it, any pre-Java 9 code not in a Java-9 module will be part of the unnamed module where anything is exposed.

I'm using this as an annotation like this in my module:

@JsonIgnore
public Week getNextWeek()
{
    Calendar instance = this.getFirstDay();
    instance.set(Calendar.WEEK_OF_YEAR, this.week + 1);
    return new Week(instance);
}

So if this is the case with the com.fasterxml.jackson.annotation package, why is the error referring to a module with that name, and why is it a problem that it does not read it?

Chuckle answered 18/6, 2018 at 14:42 Comment(3)
The error hints that you are compiling module com.fasterxml.jackson.annotation and the code in that module has a reference to a type in package com.fasterxml.jackson.annotation on the class path. Are you trying to compile com.fasterxml.jackson.annotation as an explicit module? Can you post the javac command that you are using?Coze
I'm not explictely trying to compile it. I have edited my question to show how I'm using the module.Chuckle
You're updated question makes it look like you are compiling a module but you've put the dependency on the class path rather than the module path.Coze
H
6

Quoting from the JigSaw Spec:

The unnamed module exports all of its packages. This enables flexible migration, as we shall see below. It does not, however, mean that code in a named module can access types in the unnamed module. A named module cannot, in fact, even declare a dependence upon the unnamed module.

What you're looking for are Automatic Modules. In automatic modules, a jar can be placed on the module path and will automatically derive the module name from the jar itself. In case you're using Maven, that should be the artifactId.

As such, if you are using jackson-annotations in maven as following:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.0.0</version>
</dependency>

You'd still require to define it inside your module-info.java:

module example {
    requires jackson.annotations;
}

After that, you're free to use the annotations within your module.

Habitancy answered 18/6, 2018 at 16:46 Comment(1)
Hey Jaims, I'm having this exception: Exception in thread "JavaFX Application Thread" java.lang.reflect.InaccessibleObjectException: Unable to make field private java.lang.String me.project.mosaicov2.login.LoginResponse.access_token accessible: module main does not "opens me.fullcam.mosaicov2.login" to module jackson.databind and i'm requiring jackson.annotations in my module-info. Tryied to "opens me.fullcam.mosaicov2.login to jackson.databind;" but it not compile...Etheridge

© 2022 - 2024 — McMap. All rights reserved.