I have two library plugins, each of the same library that have the same API, but different versions
One of the library plugins has the following in the MANIFEST.MF:
The second library plugin has the following defined in the MANIFEST.MF:
The plugin that uses this API has the following defined in the MANIFEST.MF:
When the plugin that is using Import-Package is activated,
it checks a preference value to determine which version of the library
the user would like to use. The Activator then calls bundle.stop() and bundle.uninstall()
for the library version that is NOT wanted, leaving only the one plugin available to satisfy the
Import-Package. Up to this point, everything functions as expected and the correct version of the
library can be used without error.
The problem comes in when changing versions. The solution we have is that when the preference
value is changed, we force the application to shutdown and ask the user to restart it so that
the platform and JVM will both restart and we can programmatically stop and uninstall
the other version of the plugin. However, when we think try to invoke the installed version of
the library after a switch, we get the following exception:
java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) previously initiated loading for a different type with name "com/package/package1/ClassName"
Restarting the JVM and Platform again without changing the preference fixes this issue, but I'd much
rather find a solution that doesn't require users to restart the application two times to change
a library version. Is there another way to solve this problem to avoid this linkage error?