Reputation: 510
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?
Upvotes: 5
Views: 8000
Reputation: 1575
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.
Upvotes: 6