开发者

java question on jar dependencies

开发者 https://www.devze.com 2023-03-05 02:35 出处:网络
I have a project that its main part (e.g. main.jar) depends on libraries (e.g. u1.jar, u2.jar etc) that has been created as distinct separate projects.

I have a project that its main part (e.g. main.jar) depends on libraries (e.g. u1.jar, u2.jar etc) that has been created as distinct separate projects.

So one could reuse the library elsewhere i.e. there is no dependency between the utility libraries and the main part.

The main part has dependencies on the libraries of course but this is ok.

Now I need to add a specific functionality in one of the libraries.

The needed functionality is already implemented.

It is implemented via a spring bean and the user can configure how the implementation will behave at runtime.

The spring application context is created and used only via the main project and so I do not have access to the spring c开发者_Python百科ontext from the utility libraries.

The problem is that I would like to reuse this implementation (and not duplicate the code) and it is not possible to move that part elsewhere

What comes to mind is to create a dependency in this specific util jar to refer to the main.jar.

I will do this to be able to have access to the spring context from the utility jar as well.

What concerns me is that now, I have a cyclic dependency between main.jar and util.jar.

I.e. main.jar already depends on util.jar and now I will create a reverse dependecy as well.

Is this a good idea to do it? Or am I into trouble (class loading issues etc)?

Is there a nice approach for these kind of issues?

Thanks


create an interface and let util.jar work with interface with main.jar passing the implementation which simply wraps this context?

cyclic dependency looks like a nightmare. Which one will you build first?


Once you see that you have cyclic dependency, you know that you have something wrong in the design. Have you thought about if you can apply the Observer Pattern ? Or try to read this one about Acyclic Relationships

0

精彩评论

暂无评论...
验证码 换一张
取 消