[Solved] JNLPClassLoader finds the same resource twice when using jnlp extension
Posted: 03 Aug 2023, 15:58
Our application uses a jnlp file ("first.jnlp") which references another jnlp file ("second.jnlp") as an extension:
first.jnlp
The second.jnlp references a jar file which contains an xml resource:
So it looks something like this:
first.jnlp --> second.jnlp (extension) --> jar --> xml resource
When calling the method getResources() of the ClassLoader with the path to the xml file as an argument, the method findResources() of the net.sourceforge.jnlp.runtime.classloader.JNLPClassLoader gets called with the same argument. This method returns an Enumeration<URL> with two occurences: the first one is empty and the second one is a Collection which contains the same resource twice. So the JNLPClassLoader seems to be finding the same resource twice, although it only exists once in one jar, which is referenced by only one jnlp. This in turn leads to the resource being processed twice in the application, which causes all sorts of problems.
The reason behind this behavoiur seems to be the fact that the resource is in a jar which is in an extension jnlp.
The JNLPClassLoader probably finds the resource once when processing the first.jnlp (seemingly also including all its extensions) ant then once more when processing the second.jnlp. So the jar seems to be on the classpath twice and not only once as expected.
I tried using only one jnlp file without extensions and referencing all the jars in this jnlp. Everything worked perfectly, this time the resource was only found and processed once, as expected.
first.jnlp
Code: Select all
...<resources>
<extension href="second.jnlp" name="myExtension"/>...
Code: Select all
...<resources>
<jar href="jar_containing_xml_resource.jar" version="1.0.0"/>...
first.jnlp --> second.jnlp (extension) --> jar --> xml resource
When calling the method getResources() of the ClassLoader with the path to the xml file as an argument, the method findResources() of the net.sourceforge.jnlp.runtime.classloader.JNLPClassLoader gets called with the same argument. This method returns an Enumeration<URL> with two occurences: the first one is empty and the second one is a Collection which contains the same resource twice. So the JNLPClassLoader seems to be finding the same resource twice, although it only exists once in one jar, which is referenced by only one jnlp. This in turn leads to the resource being processed twice in the application, which causes all sorts of problems.
The reason behind this behavoiur seems to be the fact that the resource is in a jar which is in an extension jnlp.
The JNLPClassLoader probably finds the resource once when processing the first.jnlp (seemingly also including all its extensions) ant then once more when processing the second.jnlp. So the jar seems to be on the classpath twice and not only once as expected.
I tried using only one jnlp file without extensions and referencing all the jars in this jnlp. Everything worked perfectly, this time the resource was only found and processed once, as expected.