Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Using the Java ServiceLoader to load from a Jar inside another Jar.  (Read 2006 times)
0 Members and 1 Guest are viewing this topic.
Offline quew8

JGO Knight


Medals: 53



« Posted 2014-07-16 18:43:38 »

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:
Quote
d | PRE_INIT | URL passed to URLClassLoader[0] = file:/.../ARBShaderServiceImpl.jar
d | PRE_INIT | URL passed to URLClassLoader[1] = file:/.../DefaultFramebufferServiceImpl.jar
d | PRE_INIT | URL passed to URLClassLoader[2] = file:/.../DefaultShaderServiceImpl.jar
d | PRE_INIT | URL passed to URLClassLoader[3] = file:/.../EXTFramebufferServiceImpl.jar
v | PRE_INIT | Loader: java.util.ServiceLoader[com.quew8.gutils.desktop.opengl.services.ShaderServiceImpl]
v | PRE_INIT | Loader Found: class com.quew8.gutils.desktop.opengl.services.arb.ARBShaderServiceImpl
v | PRE_INIT | Loader Found: class com.quew8.gutils.desktop.opengl.services.def.DefaultShaderServiceImpl
v | PRE_INIT | Looking At: class com.quew8.gutils.desktop.opengl.services.arb.ARBShaderServiceImpl
v | PRE_INIT |     Is Applicable: true
v | PRE_INIT |     Precedence: 2
v | PRE_INIT |     Setting As Top Implementation
v | PRE_INIT | Looking At: class com.quew8.gutils.desktop.opengl.services.def.DefaultShaderServiceImpl
v | PRE_INIT |     Is Applicable: true
v | PRE_INIT |     Precedence: 1
v | PRE_INIT |     Setting As Top Implementation
v | PRE_INIT | Looking At: class com.quew8.gutils.desktop.opengl.services.NoShaderServiceImpl
v | PRE_INIT |     Is Applicable: true
v | PRE_INIT |     Precedence: -1

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

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.
Offline quew8

JGO Knight


Medals: 53



« Reply #1 - Posted 2014-07-24 16:31:07 »

For future reference, my solution to this was not to do it. I now load my services' jars as external resources. This way makes more sense anyway and was always going to be the final method. The only reason I didn't do it in the first place was to save me writing external resource loading into my resource loading system then and there.

But the question still stands, as a query of interest and potentially to help out others in the future, if someone does know the answer.
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (74 views)
2018-06-10 19:43:48

EgonOlsen (55 views)
2018-06-10 19:43:44

EgonOlsen (74 views)
2018-06-10 19:43:20

DesertCoockie (254 views)
2018-05-13 18:23:11

nelsongames (154 views)
2018-04-24 18:15:36

nelsongames (154 views)
2018-04-24 18:14:32

ivj94 (895 views)
2018-03-24 14:47:39

ivj94 (156 views)
2018-03-24 14:46:31

ivj94 (808 views)
2018-03-24 14:43:53

Solater (172 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!