I am using the java.util.ServiceLoader to load plugins/extensions (call them what you want) from a series of Jar files which I store as resources inside my main executable Jar file. I generate an array of URLs which list the locations of the Jar files. I create an URLClassLoader and create a ServiceLoader around this class loader, and then the ServiceLoader does its stuff. Running this from my IDE (NetBeans if it makes a difference) but as soon as I build the project, the ServiceLoader fails to recognize any implementations.
To give an example (they don’t add any info but perhaps state it more clearly than I did), here is the log output after running from NetBeans:
And then from running it from the Jar.
[quote]v | PRE_INIT | URL passed to URLClassLoader[0] = jar:file:/…/StellarColony.jar!/…/ARBShaderServiceImpl.jar
v | PRE_INIT | URL passed to URLClassLoader[1] = jar:file:/…/StellarColony.jar!/…/DefaultFramebufferServiceImpl.jar
v | PRE_INIT | URL passed to URLClassLoader[2] = jar:file:/…/StellarColony.jar!/…/DefaultShaderServiceImpl.jar
v | PRE_INIT | URL passed to URLClassLoader[3] = jar:file:/…/StellarColony.jar!/…/EXTFramebufferServiceImpl.jar
v | PRE_INIT | Loader: java.util.ServiceLoader[com.quew8.gutils.desktop.opengl.services.ShaderServiceImpl]
v | PRE_INIT | Looking At: class com.quew8.gutils.desktop.opengl.services.NoShaderServiceImpl
v | PRE_INIT | Is Applicable: true
v | PRE_INIT | Precedence: -1
v | PRE_INIT | Setting As Top Implementation
[/quote]
Obviously the difference between these is the URLs and the fact that the loader doesn’t find any services (the NoShaderServiceImpl is loaded outside of the ServiceLoader in my own code)
So my question is: has anyone else experienced this and can anyone shed some light on why it is happening?
Thank you in advance.