I'm trying to load an external module.jar, which implements an Interface from my main spring application.
Therefore I implemented this solution
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
File loc = new File("plugins");
File[] flist = loc.listFiles(new FileFilter() {
public boolean accept(File file) {return file.getPath().toLowerCase().endsWith(".jar");}
});
URL[] urls = new URL[flist.length];
for (int i = 0; i < flist.length; i++) {
try {
urls[i] = flist[i].toURI().toURL();
System.out.println(flist[i].toURI().toURL().toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
URLClassLoader ucl = new URLClassLoader(urls);
ServiceLoader<DeviceInterface> sl = ServiceLoader.load(DeviceInterface.class, ucl);
Iterator<DeviceInterface> apit = sl.iterator();
while (apit.hasNext())
System.out.println(apit.next().getName());
}
Unfortunatly this throws this exception:
java.lang.NoClassDefFoundError: de/maxrakete/james/device/domain/DeviceInterface
Am I supposed to declare my main application as a dependency in my module? Currently my module only has its own dependencies.
The rescources I found online were not really clear about this issue.