I have a little Java applet game where you can choose between some themes. It works very well but the downloading time of the huge .jar is not acceptably. Now I want to split the .jar into single .jars, a default one and one for every theme. Now there is just one question: (How) can I read a .jar file from a Java applet which is also a .jar?
Asked
Active
Viewed 760 times
2 Answers
1
Take a look at the URLClassLoader
. You can give the URL to the theme.jar as a parameter and use the getResource* methods to access the files inside.
Another approach would be to manually download the JAR and open it with the java.util.jar
classes, but I would go with the first approach.

ZeissS
- 11,867
- 4
- 35
- 50
-
It doesn't work... I get this error: `java.security.AccessControlException: access denied (java.lang.RuntimePermission createClassLoader)` – Flo Edelmann Nov 04 '10 at 13:37
-
This can be a lot of things: Have you signed both jars and access the file on the same server as you originate from? – ZeissS Nov 04 '10 at 16:09
-
Thank you, it worked! I didn't know I have to sign the jars, but now I do :) – Flo Edelmann Nov 07 '10 at 12:17
1
- Deploy the applet using Java Web Start. From Java 1.2 this could be done to get a 'free floating' applet (outside a web page), but since 1.6.0_10+, it can also be done for embedded applets.
- Put each theme in a separate Jar and in the JNLP (launch file) & mark them as 'lazy' download.
- Notate which package is contained in which Jar (also in the JNLP file) so the JWS client knows which Jar to download for each theme. (a)
- Everything else will work 'like magic', and the JWS client will show a progress bar when downloading the lazy Jars.
(a) For this to work properly, each theme needs to be in a separate package, as well as a separate Jar.

Andrew Thompson
- 168,117
- 40
- 217
- 433
-
Oh, you can do the applet thing with webstart now? Nice :) Didn't know. – ZeissS Nov 04 '10 at 10:10
-
@ZeissS Check out https://jdk6.dev.java.net/plugin2/jnlp/. I am sure I saw the same document on the Oracle site the other day, but unfortunately cannot find a reference to it at this moment. – Andrew Thompson Nov 04 '10 at 13:43