如何从Java 9模块导出所有包? [英] How to export all packages from Java 9 module?

查看:546
本文介绍了如何从Java 9模块导出所有包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,对于我拥有的每个模块,我都需要明确指定要导出的包。例如:

 模块核心{
exports cc.blynk.server.core;
出口cc.blynk.server.core.protocol.handlers.decoders;
出口cc.blynk.server.core.protocol.handlers.encoders;
}

然而,这不是很方便。我想做类似的事情:

 模块核心{
exports cc.blynk.server.core。* ;
}

有没有办法做到这一点?这个限制来自哪里?

解决方案



<$ p $的用法p> 模块核心{
exports cc.blynk.server.core。*;
}

不鼓励,因为这可能会导致从不同的包中导出的不同包中的冲突这些模块违背了模块化代码的目的。






另外引用其中一个主题:


模块导出的包应该是一个稳定的API,消费者可以依赖它。出于这个原因,我们让模块作者
明确地拼出导出的包
。这也减少了多个模块不必要地导出相同包的
的可能性。
此外,它还避免了在 com.abs com.abs com.abs。*
时无条件导出时可能出现的混淆.foo

资格导出。



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?

解决方案

The usage of

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

is discouraged 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.

这篇关于如何从Java 9模块导出所有包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆