How to access resource inside jar inside webstart webapp directory using JnlpDownloadServlet

I deployed the swing GUI via webstart-maven-plugin and JnlpDownloadServlet to my webapp in the servlet container (Glassfish 3.0). My classes and GUI resources are in the mygui-4.8.jar file, which is in the webstart directory of my webapp along with the launch.jnlp file.

An application may start working normally when accessed at the launch.jnlp URL in a web browser:

http: // localhost: 8080 / myserver / webstart / launch.jnlp

However, when the code in my webapp tries to access the image resource inside the mygui-4.8.jar file, it cannot get it.

The code I use in the GUI to get the icon:

URL iconURL = getClass (). getClassLoader (). getResource ("/icons/Find.png");

Using the debugger, I see that iconURL.toString () returns the following URL:

jar: HTTP: // local: 8080 / MyServer / WebStart / mygui.jar / icons / Find.png

I noticed that the version is missing from the jar file name (this is mygui.jar instead of mygui-4.8.jar).

This seems to be due to version processing in the jnlp protocol.

Can someone tell me how can I rewrite my client code to get these resources inside the jar file? Thank you for your help.

+4
source share
1 answer

The problem is the solution!

The problem turned out to be an error elsewhere in my code and had nothing to do with webstart, jnlp or JnlpDownloadServlet. There was a flaw in the way image resources that were accidentally processed during the assembly process and as a result got damaged.

The correct way to link to resources was as I originally had the following:

String icon = "icons/Find.png"; //Notice no leading '/' URL url = getClass().getClassLoader().getResource(icon); ImageIcon imageIcon = new ImageIcon(url); 

The code works fine when the resource is inside the jar in the webstart directory of the web server. It also works great if it is found as a local file in the classpath. It works whether the application runs in javaws or as a standalone application outside of javaws.

+2
source

Source: https://habr.com/ru/post/1340199/


All Articles