简体   繁体   English

如何为不同的jar版本分离类加载器?

[英]How to separate class loader for different jar version?

I have a test war file that contains many tests. 我有一个包含许多测试的测试战争文件。 Each test is packaged in maven project with a lot of dependencies. 每个测试都打包在maven项目中,具有很多依赖性。 We use maven for dependency management but it comes with a problem. 我们使用maven进行依赖项管理,但这带来了一个问题。 When a test update a common library, it can break other test that depends on the older version of the lib. 当测试更新公共库时,它可能会破坏依赖于旧版lib的其他测试。 How to make all the test run in a completely separate environment with its own set of library version? 如何使所有测试在具有自己的库版本集的完全独立的环境中运行? I can't execute them in a separate jvm because these tests need to be executed very frequently like very 30 sec or so. 我不能在单独的jvm中执行它们,因为这些测试需要非常频繁地执行,例如大约30秒左右。 Can OSGi help solve this problem? OSGi可以帮助解决此问题吗?

Yes OSGi can solve this problem, but it is not a step to be taken lightly. 是的,OSGi可以解决此问题,但是不要轻易采取这一步骤。 Use OSGi when you are ready to commit time and effort to isolating and managing dependencies, versioning them properly and, optionally, making your code and architecture more modular/reusable. 当您准备投入时间和精力来隔离和管理依赖项,对其进行正确版本控制时,可以使用OSGi,并且可以选择使您的代码和体系结构更具模块化/可重用性。

Bear in mind that adopting OSGi can be painful at first due to non-modular practices used by some legacy libraries. 请记住,由于某些传统库使用的非模块化做法,一开始采用OSGi可能会很痛苦。

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

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