Problem and question: Java webstarted app looking for its classes in base folder instead of ./lib.
As suggested in similar question at Java Web Start applications ask repeatedly for un-existing files I have turned off the jar signing, to rule out the security issue, and the problem persists.
Below find the clean example on what is going over the network for this simple java program:
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Hello World! Initializing the class from the jar residing in lib/ folder. Expecting heavy network traffic...");
//This class resides in lib/SampleJavaLibrary.jar
//Initializing it just to excercise the class loader problem
CDummyClass sDummy = new CDummyClass();
System.out.println("Done");
}
On the network (by wireshark), one can observe repeated requests for jars in base folder, On some calls I counted up to 10 retries, replied by web server with 404. Ultimately, the loadClass is successful, but only after 10 or more requests for nonexisting jars. Multiply this with the number of classes being accessed in given program, and you end up with very slow initialization. In this simple case, there are "only" 2 retries for this simple class.
It all starts normal, the jars are loaded, all is good and nice:
6 0.020921 192.168.1.35 192.168.1.130 HTTP GET /mnt/vbox/workspace/WebStartSample/distC/launch.jnlp HTTP/1.1
8 0.028092 192.168.1.130 192.168.1.35 HTTP HTTP/1.1 200 OK (application/x-java-jnlp-file)
10 0.514038 192.168.1.35 192.168.1.130 HTTP GET /mnt/vbox/workspace/WebStartSample/distC/lib/SampleJavaLibrary.jar HTTP/1.1
11 0.520688 192.168.1.130 192.168.1.35 HTTP HTTP/1.1 200 OK (application/java-archive)
12 0.618640 192.168.1.35 192.168.1.130 HTTP GET /mnt/vbox/workspace/WebStartSample/distC/WebStartSample.jar HTTP/1.1
14 0.652541 192.168.1.130 192.168.1.35 HTTP HTTP/1.1 200 OK (application/java-archive)
This is where the trouble begins, at library class call:
16 0.943801 192.168.1.35 192.168.1.130 HTTP GET /mnt/vbox/workspace/WebStartSample/distC/SampleJavaLibrary.jar HTTP/1.1
18 0.991748 192.168.1.130 192.168.1.35 HTTP HTTP/1.1 404 Not Found (text/html)
22 0.997281 192.168.1.35 192.168.1.130 HTTP GET /mnt/vbox/workspace/WebStartSample/distC/SampleJavaLibrary.jar HTTP/1.1
24 1.004799 192.168.1.130 192.168.1.35 HTTP HTTP/1.1 404 Not Found (text/html)
Ultimately, after above retrying, the class is being found and initialized (!), most likely from the already existing jar, which was loaded at application startup.
Why is jnlp class loader looking into base folder, and why for so many retries, is beyond me. I did tried to run under debugger, but could not find the sources for class loaders and could not figure it myself.
FWIW here is my jnlp file, and yes, I did tried all variations of update tag, lazy, eager, no changes
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="http://mydebian.mydomain/mnt/vbox/workspace/WebStartSample/distC" href="launch.jnlp" spec="1.0+">
<information>
<title>WebStartSample</title>
<vendor>user</vendor>
<homepage href=""/>
<description>WebStartSample</description>
<description kind="short">WebStartSample</description>
</information>
<update check="always"/>
<resources>
<j2se version="1.5+"/>
<jar href="WebStartSample.jar" main="true"/>
<jar href="lib/SampleJavaLibrary.jar"/>
</resources>
<application-desc main-class="webstartsample.Main">
</application-desc>
</jnlp>
I suspect there is something wrong with the JNLPClassLoader(), that is the particular loader used within the webstart.
Regards,
Robert
The "mydebian.mydomain" hostname hints you are running on Debian, where OpenJDK is the default Java implementation.
The Sun Java WebStart implementation is not part of OpenJDK, so an alternative implementation is used. As Java WebStart does not have an official TCK there are subtle differences and even bugs in the OpenJDK implementation which needs to be found manually (as there is no official TCK).
I would suggest trying with a Sun JVM (e.g. on Windows) and see if the behaviour changes.
Thanks everyone for suggestions. It was Andrew hint to 'index the jars' which pointed me to the right direction...
Namely, the jars (produced my current IDE of choice, Netbeans) were indexed. However, the META-INF/INDEX.LIST within the main jar contained the references to other jars as if they were in current folder, next to the main jar.
That resulted in jnlpClassLoader(), using the main index, and looking for jars in codebase url, while they actually resided under ./lib url subfolder.
This is how the correct index (recreated manually) looks:
To make the problem worst, such webstarted application would not fail, they would just look for classes/jars in wrong places first, and then eventually find them, presumably already loaded bu jnlp loader as described in original question.
Briefly, this IS related to Netbeans build and packaging procedure.
My immediate fix was disabling the jar indexing, and that resulted in correct and minimal network traffic, and greatly improved application initialization.
To do it in Netbeans, go to Tools->Options->Miscellaneous->Ant->Properties and add
jar.index=false
Proper fix would be to make Netbeans index the jar correctly but that is the another question.
Again, thanks all for suggestions.
ps.
Recommendations:
package
element for each Jar. This element is mentioned in the Resources section of the JNLP File Syntax (also expanded in the table at the top of the page). Chase the link in the page to the (downloadable only) API Specification for further details of thepackage
element. And as an aside, the API Spec. is the single best resource on JWS. I wish Oracle would make it web-browsable.