简体   繁体   English

如何解决JAR之间的循环依赖?

[英]How to solve circular dependencies between JARs?

I am working on a big project with a lot of JARs and for sure no documentation exists!! 我正在开发一个包含大量JAR的大项目,并且肯定没有文档! :( :(

To ensure that there is no memory leakage in the application, I've used JBoss Tattletale to check for circular dependencies between Jars and unfortunately I have found many. 为了确保应用程序中没有内存泄漏,我使用了JBoss Tattletale来检查Jars之间的循环依赖关系,不幸的是我发现了很多。

Can you please guide me on how to solve circular dependencies between JARs?? 能否指导我如何解决JAR之间的循环依赖?

Thanks in advance. 提前致谢。

You can break dependencies by dependency inversion . 您可以通过依赖项反转来破坏依赖项。 To avoid and resolve circular dependencies, it helps to design a tiered architecture. 为了避免和解决循环依赖关系,有助于设计分层体系结构。

That said, the circular dependencies do not cause memory leakage. 也就是说,循环依赖不会导致内存泄漏。 But breaking circular dependencies has a lot of positive effects, mainly modularization. 但打破循环依赖有很多积极影响,主要是模块化。 This not only increases flexibility, but also helps in checking and resolving problems, memory leaks included. 这不仅增加了灵活性,还有助于检查和解决问题,包括内存泄漏。

If you do not break circular dependent packages, those behave very similar to one large, monolithic package! 如果你不打破循环依赖包,那些行为非常类似于一个大的单片包!

As well as using interfaces, you can often make structural improvements by moving classes between jars/packages. 除了使用接口之外,您还可以通过在jar /包之间移动类来进行结构改进。 Breaking up fat classes so that common responsibilities can be more easily grouped together can help with this process. 分解脂肪类以便将共同责任更容易地组合在一起可以帮助完成这个过程。 There are several commercial visualization/restructuring tools to help with this. 有几种商业可视化/重组工具可以帮助解决这个问题。

If by memory leakage , you mean more memory than necessary is consumed or my jar(s) is(are) too fat , then, you may want to investigate Proguard . 如果通过memory leakage ,你的意思more memory than necessary is consumed或者my jar(s) is(are) too fat ,那么,你可能想调查Proguard

I am creating large maven projects, with many dependencies on many libraries, which themselves have dependencies to other libraries. 我正在创建大型maven项目,许多库依赖于许多库,这些库本身与其他库有依赖关系。 However, I am not using all the code in all libraries. 但是,我没有使用所有库中的所有代码。 Proguard basically helps me trim and remove all unnecessary code. Proguard基本上帮我修剪并删除所有不必要的代码。

It is really a clean tool doing the job for me. 这对我来说真的是一个干净的工具。 I create a huge fat jar with all my dependencies, configure my entry points in my code and then it shrinks everything. 我创建了一个包含所有依赖项的巨大胖罐,在我的代码中配置我的入口点然后它缩小了所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM