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.
- 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.
精彩评论