[英]Java 9 - Cannot be resolved as a module
Very simple use case, I am using Eclipse Oxygen 4.7.3a which includes support from Java 9. I have two projects that are Java 9 projects: 非常简单的用例,我正在使用Eclipse Oxygen 4.7.3a ,其中包括Java 9的支持。我有两个项目是Java 9项目:
- projectOne
| - src
| - module-info.java
| - com
| - package1
| - first
| Classificator.java
- projectTwo
| - src
| - module-info.java
| - com
| - package2
| - second
| Classifiable.java
I want to use the Classifiable
class inside the Classificator
, so I try to import the second module into the first project. 我想用
Classifiable
内部类Classificator
,所以我尽量第二模块导入的第一个项目。
module-info.java Project 1: module-info.java项目1:
module projectOne {
requires projectTwo;
}
module-info.java Project 2: module-info.java项目2:
module projectTwo {
}
Eclipse is giving me the error: Eclipse给了我错误:
projectTwo cannot be resolved to a module
projectTwo无法解析为模块
Do I have to gather all my Java projects under one "main project" in order to let Eclipse know that all those modules are usable inside it ? 为了让Eclipse知道所有这些模块都可以在其中使用,我是否必须将所有Java项目收集在一个“主项目”下? Or something else I missed ?
还是我想念的其他东西?
No, you don't need them to be in the same directory. 不,您不需要将它们放在同一目录中。 Ideally, your
project-one
module defines some uses
, which are implements by your project-two
module (or vice-versa). 理想情况下,您
project-one
模块定义了一些uses
,这些uses
是您的第二个project-two
模块所实现的(反之亦然)。 Get the runtime implementation of your used interfaces. 获取所用接口的运行时实现。 For this, both jars/classes must be on the module path.
为此,两个jar /类都必须在模块路径上。
For further information on module build, multi module builds,... you can refer to this link . 有关模块构建,多模块构建的更多信息,...您可以参考此链接 。 Even if you do not use gradle, its tutorial on java 9 module build is quite interesting and gives some insight.
即使您不使用gradle,其有关Java 9模块构建的教程也很有趣,并提供了一些见解。
While wiring as a service is certainly a viable approach (as described in the other answer), let me add that requires
can be made to work, too, of course. 虽然将连线即服务当然是一种可行的方法(如另一个答案中所述),但我想补充一点,当然也可以使
requires
生效。
The thing that was probably missing from the first approach is: Eclipse still needs to know where to look for modules. 第一种方法可能缺少的是:Eclipse仍然需要知道在哪里寻找模块。 In real world projects this will typically be mediated by your build tool of choice plus a plug-in like m2e or buildship .
在现实世界中的项目,这将通常通过选择加一个插件像你的构建工具来介导的M2E或buildship 。
If no such plug-in is used, a normal project dependency should be added to the Build Path of project projectOne
in order to make project projectTwo
visible. 如果未使用此类插件,则应将常规项目依赖项添加到项目
projectOne
的构建路径中,以使项目projectTwo
可见。 Once the project is on the Build Path the module defined by the project can be resolved in references in module-info.java
. 一旦项目在Build Path上,就可以在
module-info.java
中的引用中解析该项目定义的模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.