开发者

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 on开发者_Python百科e question: (How) can I read a .jar file from a Java applet which is also a .jar?


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.


  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜