Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java模块和循环存在于模块依赖项、模块_Java_Packages_Modularity - Fatal编程技术网

Java模块和循环存在于模块依赖项、模块

Java模块和循环存在于模块依赖项、模块,java,packages,modularity,Java,Packages,Modularity,我有2个项目和 + proj1 has + com.myproj1 has + Runner.class + Logger.class + proj2 has + com.myproj2 has + Test.class + Fact.class module com.myproj1 { requires module com.myproj2; exports com.myproj1 } mod

我有2个项目和

+ proj1 has
    + com.myproj1 has
        + Runner.class
        + Logger.class

+ proj2 has
    + com.myproj2 has
        + Test.class
        + Fact.class

module com.myproj1 {
    requires module com.myproj2;
    exports com.myproj1
}

module com.myproj2 {
    exports com.myproj2;
    requires module com.myproj1;// the problem is "Cycle exists in module 
    dependencies, Module... "
}
我在com.myproj1 Runner.class中使用com.myproj2中的Test.class,在这里之前没有问题,但是当我尝试使用 在Fact.class中,它给了我一个问题“模块依赖项中存在循环,模块”。我知道模块是防止循环依赖的。但是
这种情况下的解决方案是什么?这是一个错误的依赖循环,因为您是如何构造模块的。 将
Logger
移动到自己的模块中,并将其导入其他两个项目中。这是一般的解决方案:排除人为导致循环的依赖项


如果你有一个真正的循环依赖,你需要重新构建整个系统来防止它,但你在这里没有这种情况。

请详细说明你的答案。我是说我还是很困惑。当我读到module1需要module2,module2需要module1时,为什么它不是循环依赖?