We have several applications that use Apache HTTPClient 3 to make HTTP requests. Recently we have also began creating web service clients that use HTTPClient 4 for various reasons. The Apache stance is that "major releases are not backwards compatible". While I would love to update all of our projects to use version 4, that's simply not feasible.
So, while my main question is rather general, my particular question is. How can I use HTTPClient version 3 and 4 in the same application? In our case an application can be a web, desktop, or command line app.
I have read the SO question for java-dynamically-load-multiple-versions-of-same-class which seems semi close but I don't care so much about the dynamic part. In fact I would like the JARs to be shipped with the app (example, WEB-INF/lib for web apps) I also see OSGi mentioned a lot in questions similar to this one but it seems to be overkill or perhaps overly complex (maybe a simple example could prove otherwise).
In the end I want to be able to hand a team a set of jars that they can drop in and it just works independent of their project using HTTP Client 3.
As others have stated, you can create multiple classloaders and load the two versions in isolation. This part is easy enough.
The problem is, this essentially splits your "class space", and it will still be very hard to refer to v3 from some parts of your application while referring to v4 from other parts of your application. You will have to partition your application very carefully... so why not just split it and deliver two applications?
OSGi could be a solution if you are able to factor out functionality into services. But converting a legacy application to OSGi is not something to take on lightly, and it will certainly not be a cheap escape from the trap that you have walked into. I say this as the author of a book on OSGi and a well-known OSGi evangelist. A long-term goal of converting your applications to OSGi would bring you great benefits, but will also involve significant up-front costs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With