Java web start and jar file resources

In my current project I have been managing resources using zip files, however want to offer a webstart deployment (especially for sharing). However I am now getting a null pointer exception on the following line, or access denied if I copy resources.jar into the main jar file:

		resources = new ZipFile(Stroll.class.getClassLoader().getResource("resources.jar").getFile());

They are stored in the same directories in the server, and this executes fine within eclipse and on the desktop. I am not trying to access anything special so I’m running in a sandbox with the following jnlp file (stroll.jnlp)
EDIT: URL above updated

<?xml version="1.0" encoding="UTF-8"?>
<jnlp codebase="http://www.thedrugzone.co.uk" href="stroll.jnlp">
<information>
     <title>Stroll: On Drugs</title>
     <vendor>Early Interventions Team</vendor>
     <icon href="/images/logoEit.gif"/>
     <homepage ref="/games.html"/>
     <offline-allowed/>
</information>
<resources>
     <j2se version="1.5+"/>
     <jar href="stroll.jar"/>
     <jar href="resources.jar"/>
</resources>
<application-desc main-class="org.konelabs.stroll.v1.execute.StrollFrame"/>
</jnlp>

surely you do not need to open resources.jar at all as it should be transparent your program that files in resources.jar are effectively in a zip container… To your program they should simpley exist as if in the path.

i.e. just use Stroll.class.getClassLoader().getResource(“PATH TO FILE WHICH EXISTS IN RESORCES.JAR”);

this will only work if the resources.jar is in the classpath(defined in the resources section of the jnlp like you have currently).

Great, thanks! I had no idea I could access the Jar’s in that way with JNLP.

I’ve never worked with webstart, but isn’t it just like normal jars concerning classpaths, resources and such? I think so…

Well normally I would read resource jars using ZipFile. In the past I used to jar the data with the class files but I prefer to keep data files separate.

One thing that I need to do is get it so that it can easily be exported as a stand alone application now without needing to modify source code for the builds. How do you manually load a Jar file so that you can access it with getResource?

You don’t. All resources should already be in your class path. I don’t know how to construct a class path with multiple jars for JNLP, but for a stand alone application, you would typically modify the manifest in your “main” jar, and insert a class-path entry there, mentioning all the other jar files you need.

Well the JNLP isn’t a problem, for that I just list the jar files in the .jnlp file. And thanks, the manifest got it working so I can easily work with one simple resource loading process for (a) JNLP and (b) JAR and © Eclipse :slight_smile:

Now the next trick would be to have a single Jar archive that contains Jar resources, though I think that could be handled with ZipEntry … will try it some time this week. Having said that, technically I can just copy all files and packages over to a single project and then export, but somehow it doesn’t seem as sophisticated!!!