Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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 2160 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  
 
 

 
hadezbladez (275 views)
2018-11-16 13:46:03

hadezbladez (153 views)
2018-11-16 13:41:33

hadezbladez (285 views)
2018-11-16 13:35:35

hadezbladez (67 views)
2018-11-16 13:32:03

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

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

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

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

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

nelsongames (2244 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!