7

I'm migrating project from Java 8 to Java 11, and modularity introduced in java 9 is giving me a headache. Couple jars have same packages, but different classes. This is giving me error

module SomeModule reads package my.package from both ModuleA and ModuleB

I wonder how to deal with cases like that, given that not all jars are under my control, refactoring is not a solution.

Naman
  • 27,789
  • 26
  • 218
  • 353
user902383
  • 8,420
  • 8
  • 43
  • 63

1 Answers1

1

One of the way is to make sure both these jars end up on the classpath in The Unnamed Module. But do take a note that

The unnamed module exports all of its packages. This enables flexible migration... 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. This restriction is intentional, since allowing named modules to depend upon the arbitrary content of the class path would make reliable configuration impossible.

Ofcourse the ideal solution would be to do a bottom up migration and ensure that no two modules expose the same package to the module that requires both of them.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • .. *given that not all jars are under my control, refactoring is not a solution* .. – Naman Nov 29 '18 at 17:45
  • And how, pray, does one accomplish "One of the way is to make sure both these jars end up on the classpath in The Unnamed Module."? If I have the interface class in one jar and one of its implementations in another jar and I put them on the classpath: BOOM! Not allowed! Without even using Jigsaw, just wanting to compile – Gwaptiva Jul 25 '22 at 12:16