Will using multiple versions of the jar in the application cause problems?

I came across an application that included several versions of jar files. For example, commons-fileupload-1.8.jar and commons-fileupload-1.6.jar.

Will this cause problems?

Thanks Raghuram

+4
source share
5 answers

Yes, this is a bad idea. What is likely to happen if you are lucky that either of the two versions, which will be the first in the class path, will satisfy all the links. If this happens, other versions of the .jar file will not make any difference. However, old code based on the old version of the library may not correctly display new versions of some classes, and therefore all kinds of strange bad things can happen.

Now, in an application with many separate class loaders, such a thing can occur if separate subsystems with separate class loaders support different versions. However, if you are talking about multiple references to .jar in a system class, then this is not the case with multiple class loaders.

+4
source

In my experience, yes. The bank that will be used will be the one that is loaded first, and which is based on the class loader, and not, I think, in a guaranteed manner. This means that some code may depend on a function in version 1.8, and then 1.6 loads and throws an exception when trying to use it.

+1
source

There will only be problems if both versions are actually loaded through the same classloader, for example. both appearing on a regular path.

It can be made to work if you download different versions using separate classloaders. Presumably the application you are looking at does this. Or they just updated the JAR and forgot to remove the old version.

+1
source

Definitely, and this can give you different results, sometimes depending on the application server, and sometimes depending on the packaging.

If your application uses the class X, which is in both banks, one of them X.class will be loaded by the class loader and say that it needs the class Y, which is in both banks, one of them will be (usually the first), but there is no guarantees that they will be from one bank.

So, if there are two versions of the same jar, you need to check why this is happening and try to remove one of them. (If you use maven, there are different ways to achieve this)

0
source

yes, this causes problems, because only one of them will actually be used depending on which one is loaded by the class loader (s) and in what order they are loaded.

0
source

Source: https://habr.com/ru/post/1303823/


All Articles