How to access a resource inside a jar inside webstart directory of webapp using JnlpDownloadServlet
I have deployed a swing GUI via webstart-maven-plugin and JnlpDownloadServlet to my webapp in a servlet container (Glassfish 3.0). My GUI classes and resources are in a mygui-4.8.jar file that is in the webstart directory of my webapp along with the launch.jnlp file.
The app is able to start fine when access by its launch.jnlp url in a web browser:
http://localhost:8080/myserver/webstart/launch.jnlp
However when code in my webapp tries to access an image resource that is inside the mygui-4.8.jar file it is unable to retrieve it.
The code I use in the GUI to get the icon is:
URL iconURL = getClass().getClassLoader().getResource("/icons/Find.png");
Using a debugger I see that the iconURL.toString() is returning the following URL:
jar:http://localhost:8080/myserver/webstart/mygui.jar!/icons/Find.png
I notice that the version is missing开发者_开发技巧 on the jar file name (is mygui.jar instead of mygui-4.8.jar).
This seems to have something to do with the version handling in jnlp protocol.
Can any one tell me what how I should rewrite my client code to get at these resources inside the jar file? Thanks for your help.
Problem in solved!
The problem turned out to be a bug elsewhere in my code and had nothing to do with webstart, jnlp, or JnlpDownloadServlet. There was a flaw in how image resources where being accidentally pre-processed during the build process and as a result getting corrupted.
The correct way to reference resources was how I had it originally as follows:
String icon = "icons/Find.png"; //Notice no leading '/'
URL url = getClass().getClassLoader().getResource(icon);
ImageIcon imageIcon = new ImageIcon(url);
Above code works fine when the resource is inside a jar in the webstart directory of the webapp. It also works fine if it is found as a local file on the classpath. It works whether the app is running within javaws or as a standalone app outside javaws.
精彩评论