This must be quite a common problem. An application depends on Library A and Library B. Library A depends on Library C-v1 (version 1 of Library C) and Library B depends on some newly introduced features in Library C-v2 (version 2 of Library C). And of course, there was some major refactoring in Library C-v2 which means it can’t be backwards compatible with Library C-v1. But Library C-v1 and Library C-v2 have the same package names and class names.
Now, it should be possible to effectively “re-namespace” Library C-v1. For example, a class called com.example.MyClass could be re-namespaced to old.com.example.MyClass. It should be completely possible to build an automated tool that takes a binary JAR and changes all the package names in this fashion.
It should also be possible to change the references in a dependent library. For example, any reference in Library A to Library C should be changed to point to the new package names.
Surely there must already be a tool available to do this?
(PS: I’m sure some clever person will mention OSGi, but I want to do this as a one-time activity).
jarjar does what you are asking:
The libraries are repackaged into your jar and renamed in the process. It also includes an Ant-Task.