Flo Edelmann
Flo Edelmann

Reputation: 2613

Read .jar file in Java applet

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?

Upvotes: 2

Views: 777

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168825

  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.
  2. Put each theme in a separate Jar and in the JNLP (launch file) & mark them as 'lazy' download.
  3. 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)
  4. 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.

Upvotes: 1

ZeissS
ZeissS

Reputation: 12135

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.

Upvotes: 1

Related Questions