在Java 9中,模块A和B将package.package打包到模块C. [英] Modules A and B export package some.package to module C in Java 9

查看:92
本文介绍了在Java 9中,模块A和B将package.package打包到模块C.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个模块,分别是模块a,模块b和模块c.当我运行我的应用程序时,我得到以下信息:

I have three modules module-a, module-b and module-c. When I run my application I get the following:

启动层初始化期间发生错误 java.lang.module.ResolutionException:模块module-a和module-b 将软件包some.package导出到模块module-c

Error occurred during initialization of boot layer java.lang.module.ResolutionException: Modules module-a and module-b export package some.package to module module-c

考虑到模块c不会导入some.package以及如何解决它,这是什么意思?

What does it mean, taking into consideration that module-c doesn't import some.package and how to fix it?

推荐答案

好像您已经创建了拆分包,表示两个模块(在您的情况下为 module-a module-b )包含相同的内容包(some.package).模块系统不允许这样做.如果您将两个模块都放在模块路径上,无论软件包是导出还是第三个模块都依赖于其他两个模块,您都会遇到此错误.

Looks like you've created a split package, meaning two modules (module-a and module-b in your case) contain the same package (some.package). The module system does not allow that. If you place both modules on the module path, you will get this error regardless of whether the package is exported or whether a third module depends on the other two.

解决方法是不创建共享同一程序包的模块.这不仅是一种技术解决方案,还可以通过确保每个模块具有特定且唯一的API来改进设计.

The fix is, not to create modules that share the same package. This is not only a technical solution, it also improves the design by making sure each module has a specific and unique API.

这篇关于在Java 9中,模块A和B将package.package打包到模块C.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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