In my Java project I’m using two different frameworks (let’s say A.jar and B.jar) and both of them require one common framework (let’s say Log4j.jar) but in two different versions. How it is treated by Java if framework A needs Log4J v1.1 and B needs Log4j v1.2? Will it cause some kind of conflict/error or will by somehow (how?) resolved?
If it will not cause conflict/error (my project can be compiled and run) – can I use any version of Log4j myself in this project? Or am I forced to select lower / higher version number of Log4j?
Update: to be more specific…
What if some part of Log4j API changed in v1.2 (let’s say one single method doIt() signature changed) and both A and B call doIt. What will happend? Will my project run? Will it crash on first use of doIt? What version of Log4j I must put on classpath – v1.2 or both?
Java doesn’t natively support the management of multiple versions of the same piece of code, that is, you can only use at most one version within the same JVM (with the default class loader). However, checkout question 1705720, which has several answers pointing out possible ways of achieving that (OSGi or custom class loaders).
But I doubt it worth the trouble as multiple log4j versions are not required by your code directly. In you case, I’d suggest to start from using the newer log4j version (v1.2) first and verify if it would cause any problem for framework A. If it does cause conflict, then fall-back to log4j v1.1 and verify again. If you really are out of luck, then you need to get your hands dirty…
Update: for you specific description, there’s no way of using either log4j v1.1 or v1.2, as framework A and B each require different signature. You have to roll your own version of any of log4j or framework A, or B.