I am currently writing an Eclipse Plug-In
with dependencies to external, third-party JARs. When I configure all dependencies in the Runtime
tab of my plug-in, everything works out fine.
However, the libraries I use may vary from installation to installation (and are themselves no plug-ins), so I would need a way to configure the classpath of my plug-in during runtime (or Eclipse start-up).
I tried loading the classes I need by using a URLClassLoader
which works out fine. However, the third-party libraries themselves have dependencies too and do not use my URLClassLoader
but the default class loader (which, in Eclipse, is org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader
). Setting the Thread.currentThread().setContextClassLoader()
did not help.
My last and desperate try was changing to SystemClassLoader
by reflection (according to this StackOverflow question, but that doesn't seem to have any impact on the Eclipse Plug-In
.
URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class clazz= URLClassLoader.class;
// Use reflection
Method method= clazz.getDeclaredMethod("addURL", new Class[] { URL.class });
method.setAccessible(true);
method.invoke(classLoader, new Object[] { url });
Does anyone have an idea how I can either add JARs to the classpath during plug-in execution or maybe define a folder and all containing JARs will be added to the classpath automatically? Thanks for your help!