I have several third party JARs which will be used by my webapps. These JAR files are actually available in different versions.
E.g.
Version 1.0 JARs
/opt/lib/third-party-jars/1.0/3rdparty1.jar
/opt/lib/third-party-jars/1.0/3rdparty2.jar
Version 2.0 JARs
/opt/lib/third-party-jars/2.0/3rdparty1.jar
/opt/lib/third-party-jars/2.0/3rdparty2.jar
Is it possible to load a different version of library dynamically before the servlet get loaded? Is any framework able to do this without changing my existing code?
public class Servlet1 extends HttpServlet {
protected void doPost(....) {
MyBusinessLogic businessLogic = new MyBusinessLogic();
businessLogic.run() // My business logic spawns here which will start involving third-party classes
}
}
Or is it possible to load version 1.0 or 2.0 library dynamically in the code before my business logic get invoked? One approach I can come up is using custom classloader and "setContextClassLoader" but this requires to refactor all my business logic using reflection. This will be a huge effort. I am trying not to change my existing business logic code.