How to add maven dependencies of json to modules in >= Java 9

huidube :

in java 8 projects you simply add the following dependencys in maven

<dependency>
    <groupId>javax.json</groupId>
    <artifactId>javax.json-api</artifactId>
    <version>1.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.1</version>
</dependency>

Using OpenJDK, Eclipse 2018-12
and maven module, it results in getting a error in the module-info.java:

The package javax.json.stream is accessible from more than one module: java.json, org.glassfish.java.json

So in both dependency projects there is a package called javax.json.stream and due to jigsaw module system this is not allowed anymore?

How to fix this?

EDIT:
I updated the maven dependency to 1.1.4 and put them on the classpath. The javax.json-api has a module-info.java file and is working fine, eclipse shows no more errors.
But now the packages of the implementation javax.json (org.glassfish) are not found, resulting in a ClassNotFoundException: org.glassfish.json.JsonProviderImpl

What more can I do?

EDIT:
Its working now, i forgot to generate a module-info.java in this project.

Naman :

So in both dependency projects there is a package called javax.json.stream and due to jigsaw module system this is not allowed anymore?

This is still allowed, but with both those dependencies getting resolved on the classpath instead of modulepath i.e. in the unnamed module.

Another alternative to fix this while you create your library as modular is to make sure to fix the downstream libraries exporting the same package which would require a bottom-up migration and you might have to wait for them to fix it in their latest update(or check if one is already out) and then to rely on them.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=102205&siteId=1