How to export all packages from Java 9 module? [duplicate]
Asked Answered
S

1

18

Right now, for every module I have, I need to explicitly specify packages I want to export. For example:

module core {
    exports cc.blynk.server.core;
    exports cc.blynk.server.core.protocol.handlers.decoders;
    exports cc.blynk.server.core.protocol.handlers.encoders;
}

However, it is not very convenient. I would like to do something like that:

module core {
    exports cc.blynk.server.core.*;
}

Is there any way to do that? Where this limitation comes from?

Spectrophotometer answered 30/9, 2017 at 12:23 Comment(0)
M
17

No, you can not use a wildcard to export all packages within the module. You will have to export each package explicitly.

It is not allowed since this could majorly lead to conflicts in the different packages exported from different modules which defies the purpose of modularising the code.


Additionally quoting from one of the threads:

The packages exported by a module are meant to be a stable API that consumers can rely on. For this reason, we make the module author spell out the exported packages explicitly. This also dials down the likelihood of multiple modules needlessly exporting the same package. Additionally, it avoids the confusion that would occur if com.abs.* was exported without qualification while com.abs.foo was exported with qualification.

Mccluskey answered 30/9, 2017 at 12:25 Comment(8)
This is a big problem for library devs..Dyandyana
Does not work. Gives Syntax error on token "*", Identifier expectedJunker
@Junker what didn't work for you? did you read the part of the answer "...we make the module author spell out the exported packages explicitly." explaining why * wouldn't work.Mccluskey
"The usage of X is discouraged ..." implies that X can still be used.Junker
@Junker alright, I should have used a better word I believe, have edited, any other suggestions?Mccluskey
I've made an edit suggestionJunker
whole jigsaw was a damn mistake ffsBrister
@Brister indeed, I get biblical headaches from this. It annoys the F out of me.Mastectomy

© 2022 - 2024 — McMap. All rights reserved.