0

We have a process which needs to refer two different encryption classes having same name, at different times. Both the class names are same with same package path "com.abc.security.encryption".

Both the classes have same package name com.abc.security.encryption, however they are present in different jar files.

Let's say ENCRYPTION.class(new logic) present in Jar A and ENCRYPTION.class(old logic) is present in Jar B. Now in my process, when we call Jar B API which refers ENCRYPTION.class, is referring to ENCRYPTION.class(new logic) present in Jar A instead of ENCRYPTION.class(old logic) present in Jar B .

Until I delete Jar A having ENCRYPTION.class(new logic), the ENCRYPTION.class(old logic) present in Jar B is not referred.

Since both the encryption logic are from different utility modules being used by many different modules, i am not able to ask them to change the name of the package.

I need a way to make sure both the logic are referred at required places without changing anything in those modules. Can anything be changed in the class paths of my process or in the code, so that calling Jar B API, calls ENCRYPTION.class(old logic) present in Jar B itself. And when i call direct ENCRYPTION.class it should refer to ENCRYPTION.class(new logic) present in Jar A.

Tried by adding the first class path as "." for the process. But it did not solve the issue. Your help is most appreciated.

Thanks, Nvn

randominstanceOfLivingThing
  • 16,873
  • 13
  • 49
  • 72
Nvn
  • 1
  • 1
  • This isn't an answer to your question, but don't name things like this. It isn't supported, as far as I know. – nhouser9 Apr 21 '16 at 03:41
  • It is done in other modules which cannot be changed by us. Need a solution to call both of them at different intervals. – Nvn Apr 21 '16 at 06:54

1 Answers1

0

You should remove the problematic jar from the classpath. A classpath with multiple jars that contain the same fully qualified class names is a recipe for disaster.

If that's not an option, you might be able to create a custom class loader which does this swapping. But it probably won't be easy. There's a similar question about this which might get you started if you go down this road: Unloading classes in java?

Roman
  • 3,050
  • 3
  • 21
  • 20
  • I cannot remove any jars from class path as both jars are required at different intervals. – Nvn Apr 21 '16 at 17:31